Advertisement
Guest User

foodForPets

a guest
Apr 2nd, 2020
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.     let days = Number(input.shift());
  3.     let food = Number(input.shift());
  4.  
  5.     let biscuits = 0;
  6.     let dogEaten = 0;
  7.     let catEaten = 0;
  8.  
  9.     for (i = 1; i <= days; i++) {
  10.         let dogFood = Number(input.shift());
  11.         let catFood = Number(input.shift());
  12.  
  13.         dogEaten += dogFood;
  14.         catEaten += catFood;
  15.  
  16.         if (i % 3 == 0){
  17.             biscuits += (dogFood + catFood) * 0.1;
  18.         }
  19.       }
  20.       let totalEaten = dogEaten + catEaten;
  21.  
  22.       console.log(`Total eaten biscuits: ${Math.round(biscuits)}`)
  23.       console.log(`${(totalEaten / food * 100).toFixed(2)}% of the food has been eaten.`)
  24.       console.log(`${(dogEaten / totalEaten * 100).toFixed(2)}% eaten from the dog.`)
  25.       console.log(`${(catEaten / totalEaten * 100).toFixed(2)}% eaten from the cat.`)
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement