Advertisement
Liliana797979

viarno reshenie cinema voucher

Feb 3rd, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function solve(input) {
  3.   let voucherValue = Number(input.shift());
  4.   let tickets = 0;
  5.   let other = 0;
  6.  
  7.   let next = input.shift();
  8.   while (next !== 'End') {
  9.     let price = 0;
  10.     if (next.length > 8) {
  11.       price = next.charCodeAt(0) + next.charCodeAt(1);
  12.     } else {
  13.       price = next.charCodeAt(0);
  14.     }
  15.  
  16.     if (price > voucherValue) {
  17.       break;
  18.     }
  19.  
  20.     voucherValue -= price;
  21.     if (next.length > 8) {
  22.       tickets++;
  23.     } else {
  24.       other++;
  25.     }
  26.  
  27.     next = input.shift();
  28.   }
  29.  
  30.   console.log(tickets);
  31.   console.log(other);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement