SHARE
TWEET

04. Easter Eggs Battle

MartinGeorgiev Apr 27th, 2019 198 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.     $eggsPlayerOne = intval(readline());
  4.     $eggsPlayerTwo = intval(readline());
  5.     $eggsOneCount = $eggsPlayerOne;
  6.     $eggsTwoCount = $eggsPlayerTwo;
  7.     $winner = readline();
  8.     while ($winner != 'End of battle') {
  9.            if ($winner == 'one') {
  10.                   $eggsTwoCount --;
  11.                   if ($eggsTwoCount == 0) {
  12.                          printf("Player two is out of eggs. Player one has %d eggs left.", $eggsOneCount);
  13.                         return;
  14.                   }
  15.            } else if ($winner == 'two') {
  16.                   $eggsOneCount --;
  17.                   if ($eggsOneCount == 0) {
  18.                          printf("Player one is out of eggs. Player two has %d eggs left.", $eggsTwoCount);
  19.                         return;
  20.                   }
  21.            }
  22.            $winner = readline();
  23.     }
  24.  
  25.     printf("Player one has %d eggs left.\n", $eggsOneCount);
  26.     printf("Player two has %d eggs left.\n", $eggsTwoCount);
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