Liliana797979

viarno reshenie good mine

Feb 27th, 2021
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function solve(input) {
  3.     index=0;
  4.     let locations = Number(input[index]);
  5.     index++;
  6.  
  7.     for (let i = 0;i<locations;i++){
  8.         sumGold=0;
  9.  
  10.         let expectedAverageGoldPerDay = Number(input[index]);
  11.         index++;
  12.         let daysPerLocation = Number(input[index]);
  13.         index++;
  14.  
  15.         for(let j =0;j<daysPerLocation;j++){
  16.             let currentDayGold = Number(input[index]);
  17.             index++;
  18.             sumGold+=currentDayGold/daysPerLocation;
  19.  
  20.         }
  21.         if(sumGold>=expectedAverageGoldPerDay){
  22.             console.log(`Good job! Average gold per day: ${sumGold.toFixed(2)}.`);
  23.         }else if (sumGold<expectedAverageGoldPerDay){
  24.             console.log(`You need ${(expectedAverageGoldPerDay-sumGold).toFixed(2)} gold.`);
  25.         }
  26.     }
  27. }
  28. solve(["2",
  29.     "10",
  30.     "3",
  31.     "10",
  32.     "10",
  33.     "11",
  34.     "20",
  35.     "2",
  36.     "20",
  37.     "10"]);
Advertisement
Add Comment
Please, Sign In to add comment