mark79

Cinema Tickets

Apr 20th, 2019
1,993
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $totalTicketCount = 0;
  4. $studentTicketCount = 0;
  5. $standardTicketCount = 0;
  6. $kidTicketCount = 0;
  7.  
  8. $input = readline();
  9. while ($input != "Finish") {
  10.     $freeSeats = intval(readline());
  11.  
  12.     $currentTicketCount = 0;
  13.  
  14.     $inputCurrentTicket = readline();
  15.     while ($inputCurrentTicket != "End") {
  16.         $currentTicketCount++;
  17.         switch ($inputCurrentTicket) {
  18.             case "student":
  19.                 $studentTicketCount++;
  20.                 break;
  21.             case "standard":
  22.                 $standardTicketCount++;
  23.                 break;
  24.             case "kid":
  25.                 $kidTicketCount++;
  26.                 break;
  27.         }
  28.         if ($currentTicketCount == $freeSeats) {
  29.             break;
  30.         }
  31.         $inputCurrentTicket = readline();
  32.     }
  33.     printf("%s - %.2f%% full." . PHP_EOL, $input, $currentTicketCount / $freeSeats * 100);
  34.     $totalTicketCount += $currentTicketCount;
  35.  
  36.     $input = readline();
  37. }
  38. printf("Total tickets: %d" . PHP_EOL, $totalTicketCount);
  39. printf("%.2f%% student tickets." . PHP_EOL, $studentTicketCount / $totalTicketCount * 100);
  40. printf("%.2f%% standard tickets." . PHP_EOL, $standardTicketCount / $totalTicketCount * 100);
  41. printf("%.2f%% kids tickets." . PHP_EOL, $kidTicketCount / $totalTicketCount * 100);
RAW Paste Data