kStoikow

cinema

Jul 5th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function qwe(input) {
  2.     let capacity = Number(input.shift());
  3.     let command = input.shift();
  4.     let totalSum = 0;
  5.  
  6.  
  7.     while (command !== 'Movie time!') {
  8.         let groupToCome = Number(command);
  9.         if (groupToCome > capacity) {
  10.             console.log('The cinema is full.');
  11.             break;
  12.         } else {
  13.             if (groupToCome % 3 === 0) {
  14.                 totalSum += (groupToCome * 5) - 5;
  15.             } else {
  16.                 totalSum += groupToCome * 5;
  17.             }
  18.             capacity -= groupToCome;
  19.         }
  20.         command = input.shift();
  21.     }
  22.     if (command === 'Movie time!') {
  23.         console.log(`There are ${capacity} seats left in the cinema.`);
  24.     }
  25.  
  26.     console.log(`Cinema income - ${totalSum} lv.`);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment