SHARE
TWEET

06. Cinema Tickets

MartinGeorgiev Apr 21st, 2019 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $command = readline(); //Rocky 4
  4.  
  5. $kid = 0;
  6. $standard = 0;
  7. $student = 0;
  8. $total = 0;
  9.  
  10. while ($command != "Finish") {
  11.     $count = intval(readline());
  12.     $current = 0;
  13.     for ($i = 0; $i < $count; $i++) {
  14.         $type = readline(); //student
  15.         if ($type == "End") {
  16.             break;
  17.         } else if ($type == "kid") {
  18.             $kid++;
  19.             $current++;
  20.         } else if ($type == "standard") {
  21.             $standard++;
  22.             $current++;
  23.         } else if ($type == "student") {
  24.             $student++;
  25.             $current++;
  26.         }
  27.     }
  28.     $total += $current;
  29.     $percent = $current / $count * 100;
  30.     $format = number_format($percent, 2, '.', '');
  31.     //Taxi - 60.00% full.
  32.     echo "$command - $format% full." . PHP_EOL;
  33.  
  34.  
  35.     $command = readline();
  36. }
  37. $studentPer = number_format($student / $total * 100, 2, '.', '');
  38. $standardPer = number_format($standard / $total * 100, 2, '.', '');
  39. $kidPer = number_format($kid / $total * 100, 2, '.', '');
  40. echo "Total tickets: $total" . PHP_EOL;
  41. echo "$studentPer% student tickets." . PHP_EOL;
  42. echo "$standardPer% standard tickets." . PHP_EOL;
  43. echo "$kidPer% kids tickets." . PHP_EOL;
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