SHARE
TWEET

04.Darts

MartinGeorgiev Apr 18th, 2019 (edited) 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top