Advertisement
Guest User

SuitcasesLoaded

a guest
Apr 5th, 2020
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.     let planeCapacity = Number(input.shift());
  3.  
  4.     let suitcasesCount = 0;
  5.  
  6.     while (true){
  7.         let suitcase = input.shift();
  8.  
  9.         if (suitcase == 'End'){
  10.             console.log(`Congratulations! All suitcases are loaded!`)
  11.             break;
  12.         }
  13.  
  14.         suitcasesCount += 1;  
  15.  
  16.         if (suitcasesCount % 3 == 0){
  17.             planeCapacity -= suitcase * 1.1
  18.         }
  19.         else{
  20.             planeCapacity -= suitcase
  21.         }
  22.          
  23.         if (planeCapacity <= 0){
  24.             console.log(`No more space!`)
  25.             suitcasesCount -= 1
  26.             break;
  27.         }    
  28.     }
  29.     console.log(`Statistic: ${suitcasesCount} suitcases loaded.`)
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement