Advertisement
Liliana797979

vqrno reshenie na food for pets

Jan 1st, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1function solve(input) {
  2. 2.      let index = 0;
  3. 3.      let days = Number(input[index]);
  4. 4.      index++;
  5. 5.      let foodQuantity = Number(input[index]);
  6. 6.      index++;
  7. 7.      let dogQuantity = Number(input[index]);
  8. 8.      index++;
  9. 9.      let catQuantity = Number(input[index]);
  10. 10.     index++;
  11. 11.     let currentDay = 1;
  12. 12.     let dogFood = 0;
  13. 13.     let catFood = 0;
  14. 14.     let biscuits = 0;
  15. 15.  
  16. 16.     while (currentDay <= days) {
  17. 17.         if (currentDay % 3 == 0) {
  18. 18.             biscuits += (dogQuantity + catQuantity) * 0.1;
  19. 19.         }
  20. 20.  
  21. 21.         dogFood += dogQuantity;
  22. 22.         catFood += catQuantity;
  23. 23.         dogQuantity = Number(input[index]);
  24. 24.         index++;
  25. 25.         catQuantity = Number(input[index]);
  26. 26.         index++;
  27. 27.         currentDay++;
  28. 28.     }
  29. 29.  
  30. 30.     let total = dogFood + catFood;
  31. 31.     let dogP = ((dogFood / total) * 100).toFixed(2);
  32. 32.     let catP = ((catFood / total) * 100).toFixed(2);
  33. 33.     let totalP = ((total / foodQuantity) * 100).toFixed(2);
  34. 34.     console.log(`Total eaten biscuits: ${Math.round(biscuits)}gr.`);
  35. 35.     console.log(`${totalP}% of the food has been eaten.`);
  36. 36.     console.log(`${dogP}% eaten from the dog.`);
  37. 37.     console.log(`${catP}% eaten from the cat.`);
  38. 38. }
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement