Advertisement
dimoBs

Untitled

Oct 29th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. function solve(input) {
  2. let cleaningStuff = input.shift();
  3. let cleaningStuffQ = cleaningStuff * 750;
  4. let sumOfWashes = 0;
  5. let plate = 0;
  6. let pots = 0;
  7. let counter = 1;
  8. // за 1 чиния са нужни 5 мл., а за тенджера 15 мл
  9. while (true) {
  10. let command = input.shift();
  11. if (command === "End") {
  12. break;
  13. }
  14. if (counter % 3 == 0) {
  15. sumOfWashes += command * 15;
  16. } else {
  17. sumOfWashes += command * 5;
  18. }
  19. if (sumOfWashes > cleaningStuffQ) {
  20. break;
  21. }
  22. if (counter % 3 ==0){
  23. pots += Number(command);
  24. }else {
  25. plate +=Number(command);
  26. }
  27. counter++;
  28. }
  29. if (cleaningStuffQ>= sumOfWashes){
  30. console.log("Detergent was enough!");
  31. console.log(`${plate} dishes and ${pots} pots were washed.`);
  32. console.log(`Leftover detergent ${cleaningStuffQ-sumOfWashes} ml.`);
  33.  
  34. }else {
  35. console.log(`Not enough detergent, ${Math.abs(cleaningStuffQ-sumOfWashes)} ml. more necessary!`);
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement