SHARE
TWEET

03.Froggy

MartinGeorgiev Jun 30th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $frogs = explode(" ", readline());
  3.  
  4.  
  5. $input = readline();
  6. while (true) {
  7.     $args = explode(" ", $input);
  8.     $command = $args[0];
  9.  
  10.     if ($command === "Print") {
  11.         $orientation = $args[1];
  12.         echo "Frogs: ";
  13.         if ($orientation === "Normal") {
  14.             echo implode(" ", $frogs);
  15.         } else {
  16.             echo implode(" ", array_reverse($frogs));
  17.         }
  18.         break;
  19.     } else if ($command === "Join") {
  20.         $name = $args[1];
  21.         $frogs[] = $name;
  22.     } else if ($command === "Dive") {
  23.  
  24.         $index = intval($args[1]);
  25.         if ($index >= 0 && $index < count($frogs)) {
  26.             array_splice($frogs, $index, 1);
  27.         }
  28.     } else if ($command === "First") {
  29.         $count = intval($args[1]);
  30.         for ($i = 0; $i < count($frogs); $i++) {
  31.             if ($count == 0) {
  32.                 break;
  33.             }
  34.             echo $frogs[$i] . " ";
  35.             $count--;
  36.         }
  37.         echo PHP_EOL;
  38.     } else if ($command === "Last") {
  39.         $count = intval($args[1]);
  40.         for ($i = count($frogs) - min($count,count($frogs)); $i < count($frogs); $i++) {
  41.             echo $frogs[$i] . " ";
  42.         }
  43.         echo PHP_EOL;
  44.     } else if ($command === "Jump") {
  45.         $name = $args[1];
  46.         $index = intval($args[2]);
  47.         if ($index >= 0 && $index < count($frogs)) {
  48.             array_splice($frogs, $index, 0, $name);
  49.         }
  50.     }
  51.  
  52.     $input = readline();
  53. }
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