Advertisement
MartinGeorgiev

04.Darts

Apr 18th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <?php
  2.  
  3. $name = readline();
  4.  
  5. $startPoints = 301;
  6. $success = 0;
  7. $fails = 0;
  8. $hasRetired = false;
  9.  
  10. while ($startPoints > 0) {
  11.     $field = readline();
  12.     if ($field == "Retire") {
  13.         $hasRetired = true;
  14.         break;
  15.     }
  16.     $points = intval(readline());
  17.  
  18.     switch ($field) {
  19.         case "Double":
  20.             $points *= 2;
  21.             break;
  22.         case "Triple":
  23.             $points *= 3;
  24.             break;
  25.     }
  26.  
  27.     if ($points > $startPoints) {
  28.         $fails++;
  29.     } else {
  30.         $success++;
  31.         $startPoints -= $points;
  32.     }
  33. }
  34.  
  35. if ($hasRetired) {
  36.     echo "$name retired after $fails unsuccessful shots.";
  37. } else {
  38.     echo "$name won the leg with $success shots.";
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement