Advertisement
RRusev77

Christmas

Apr 26th, 2020
487
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 length = input.length;
  4.     let money = 0;
  5.     let wonGames = 0;
  6.     let lostGames = 0;
  7.     let totalMoney = 0;
  8.     let totalLostGames = 0;
  9.     let totalWonGames = 0;
  10.  
  11.     for(let k = 1; k <= days; k++) {
  12.         wonGames = 0;
  13.         lostGames = 0;
  14.         money = 0;
  15.         for(let i = 1; i < length; i++) {
  16.             let sport = input.shift();
  17.             let result = input.shift();
  18.  
  19.             if(sport == 'Finish') {
  20.                 input.unshift(result);
  21.                 break;
  22.             }
  23.  
  24.             if(result == 'win') {
  25.                 money += 20;
  26.                 wonGames++;
  27.             } else {
  28.                 lostGames++;
  29.             }
  30.         }
  31.  
  32.         totalWonGames += wonGames;
  33.         totalLostGames += lostGames
  34.         if(wonGames > lostGames) {
  35.             totalMoney += money * 1.1;
  36.            
  37.         } else {
  38.             totalMoney += money;
  39.         }
  40.     }
  41.  
  42.     if(totalWonGames > totalLostGames) {
  43.         totalMoney *= 1.2;
  44.         console.log(`You won the tournament! Total raised money: ${totalMoney.toFixed(2)}`);
  45.     } else {
  46.         console.log(`You lost the tournament! Total raised money: ${totalMoney.toFixed(2)}`);
  47.     }
  48. }
  49.  
  50. // solve(2, 'volleyball', 'win', 'football', 'lose', 'basketball', 'win', 'Finish', 'golf', 'win', 'tennis', 'win', 'badminton', 'win', 'Finish');
  51. solve(3, "darts", "lose", "handball", "lose", 'judo', 'win', "Finish", "snooker", "lose", "swimming", "lose", "squash", "lose", "table tennis", "win", "Finish", "volleyball", "win", "basketball", "win", "Finish" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement