DimiPetrov

PB - Cinema

Jun 4th, 2020
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.    let seats = Number(input[0]);
  3.    let people = 0;
  4.    let income = 0;
  5.    let index = 1;
  6.    let command = input[index];
  7.    index++;
  8.  
  9.    while(command !== 'Movie time!' && people + command <= seats) {
  10.        people += command;
  11.        if(command % 3 === 0) {
  12.            income += command * 5 - 5;
  13.        } else {
  14.            income += command * 5;
  15.        }
  16.        command = input[index];
  17.        index++;
  18.    }
  19.  
  20.    if(people > seats) {
  21.        console.log(`The cinema is full.`);
  22.        console.log(`Cinema income - ${income} lv.`);
  23.    } else {
  24.        console.log(`There are ${seats - people} seats left in the cinema.`);
  25.        console.log(`Cinema income - ${income} lv.`);
  26.    }
  27. }
RAW Paste Data