SHARE
TWEET

04. Cinema Voucher

MartinGeorgiev Apr 20th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $voucher = intval(readline());
  4.  
  5. $totalItems = 0;
  6. $totalMovies = 0;
  7.  
  8. while ($voucher > 0) {
  9.     $item = readline();
  10.     if ($item == 'End') {
  11.         break;
  12.     }
  13.     if (strlen($item) > 8) {
  14.         $movieMoney = ord($item[0]) + ord($item [1]);
  15.         if ($voucher >= $movieMoney) {
  16.             $voucher -= $movieMoney;
  17.             $totalMovies++;
  18.         } else {
  19.             break;
  20.         }
  21.  
  22.     } else if (strlen($item) <= 8) {
  23.         $itemMoney = ord($item[0]);
  24.         if ($voucher >= $itemMoney) {
  25.             $totalItems++;
  26.             $voucher -= $itemMoney;
  27.         } else {
  28.             break;
  29.         }
  30.     }
  31. }
  32. echo $totalMovies . PHP_EOL;
  33. echo $totalItems;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top