Spocoman

Oscars

Feb 25th, 2022 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function oscars(input) {
  2.     let name = input[0];
  3.     let points = Number(input[1]);
  4.     let juryNum = Number(input[2]);
  5.  
  6.     for (let i = 3; i < juryNum * 2 + 3; i++) {
  7.         let juryName = input[i++];
  8.         let currentPoint = Number(input[i]);
  9.  
  10.         points += juryName.length * currentPoint / 2;
  11.  
  12.         if (points > 1250.5) {
  13.             break;
  14.         }
  15.     }
  16.  
  17.     if (points > 1250.5) {
  18.         console.log(`Congratulations, ${name} got a nominee for leading role with ${points.toFixed(1)}!`);
  19.     } else {
  20.         console.log(`Sorry, ${name} you need ${(1250.5 - points).toFixed(1)} more!`);
  21.     }
  22. }
  23.  
  24. Решение със shift():
  25.  
  26. function oscars(input) {
  27.     let name = input.shift();
  28.     let points = Number(input.shift());
  29.     let juryNum = Number(input.shift());
  30.  
  31.     for (let i = 0; i < juryNum; i++) {
  32.         let juryName = input.shift();
  33.         let currentPoint = Number(input.shift());
  34.  
  35.         points += juryName.length * currentPoint / 2;
  36.  
  37.         if (points > 1250.5) {
  38.             break;
  39.         }
  40.     }
  41.  
  42.     if (points > 1250.5) {
  43.         console.log(`Congratulations, ${name} got a nominee for leading role with ${points.toFixed(1)}!`);
  44.     } else {
  45.         console.log(`Sorry, ${name} you need ${(1250.5 - points).toFixed(1)} more!`);
  46.     }
  47. }
  48.  
  49.  
  50. Решение с while и shift():
  51.  
  52. function oscars(input) {
  53.     let name = input.shift();
  54.     let points = Number(input.shift());
  55.     let juryNum = Number(input.shift());
  56.  
  57.     while (juryNum-- !== 0 && points < 1250.5) {
  58.         let juryName = input.shift();
  59.         let currentPoint = Number(input.shift());
  60.  
  61.         points += juryName.length * currentPoint / 2;
  62.     }
  63.  
  64.     if (points > 1250.5) {
  65.         console.log(`Congratulations, ${name} got a nominee for leading role with ${points.toFixed(1)}!`);
  66.     } else {
  67.         console.log(`Sorry, ${name} you need ${(1250.5 - points).toFixed(1)} more!`);
  68.     }
  69. }
  70.  
Add Comment
Please, Sign In to add comment