Created
September 27, 2016 15:45
-
-
Save ryosism/64825a5b1d47fc8872ef088e8f1eccd6 to your computer and use it in GitHub Desktop.
【Level.1】CTOからの挑戦状2016 2nd~GistURL回答~
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 手続き | |
function selectOptimumCombination(amount, myCoupons) { | |
var selectedCoupons = [0, 0, 0]; | |
if(amount>1000){ | |
while(myCoupons[0]>0){ | |
if(amount<500) break; | |
amount=amount-500; | |
myCoupons[0]--; | |
selectedCoupons[0]++; | |
} | |
while(myCoupons[1]>0){ | |
if(amount<200) break; | |
amount=amount-200; | |
myCoupons[1]--; | |
selectedCoupons[1]++; | |
} | |
while(myCoupons[2]>0){ | |
if(amount<100) break; | |
amount=amount-100; | |
myCoupons[2]--; | |
selectedCoupons[2]++; | |
} | |
} | |
return selectedCoupons; | |
} | |
// ケース3 | |
console.log(selectOptimumCombination(1210, [2, 1, 3])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment