vprichkapova

Untitled

Feb 8th, 2020
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function solve(input) {
  2. let capacity = +input.shift();
  3.  
  4. let isFull = false;
  5.  
  6. let suitcaseCounter = 0;
  7. let command = input.shift();
  8. while (command !== "End") {
  9. let suitCase = Number(command);
  10. suitcaseCounter++;
  11. if (suitcaseCounter % 3 == 0) {
  12. suitCase += suitCase * 0.1;
  13. }
  14. capacity -= suitCase;
  15.  
  16. if (capacity <= 0) {
  17. isFull = true;
  18. break;
  19. }
  20.  
  21. command = input.shift();
  22. }
  23. if (command == "End") {
  24. console.log(`Congratulations! All suitcases are loaded!`);
  25. }
  26. if (isFull) {
  27. console.log("No more space!");
  28. }
  29. console.log(`Statistic: ${suitcaseCounter} suitcases loaded.`);
  30. }
  31. //solve(["550", "100", "252", " 72", "End"]);
  32. solve(["700.5", "180", "340.6", " 126", "220"]);
Advertisement
Add Comment
Please, Sign In to add comment