Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let capacity = +input.shift();
- let isFull = false;
- let suitcaseCounter = 0;
- let command = input.shift();
- while (command !== "End") {
- let suitCase = Number(command);
- if (suitcaseCounter % 3 == 0) {
- suitCase += suitCase * 0.1;
- }
- capacity -= suitCase;
- if (capacity <= 0) {
- isFull = true;
- break;
- }
- suitcaseCounter++;
- command = input.shift();
- }
- if (command == "End") {
- console.log(`Congratulations! All suitcases are loaded!`);
- }
- if (isFull) {
- console.log("No more space!");
- }
- console.log(`Statistic: ${suitcaseCounter} suitcases loaded.`);
- }
- //solve(["550", "100", "252", "72", "End"]);
- //solve(["700.5", "180", "340.6", "126", "220"]);
Add Comment
Please, Sign In to add comment