Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $frogs = explode(" ", readline());
- $input = readline();
- while (true) {
- $args = explode(" ", $input);
- $command = $args[0];
- if ($command === "Print") {
- $orientation = $args[1];
- echo "Frogs: ";
- if ($orientation === "Normal") {
- echo implode(" ", $frogs);
- } else {
- echo implode(" ", array_reverse($frogs));
- }
- break;
- } else if ($command === "Join") {
- $name = $args[1];
- $frogs[] = $name;
- } else if ($command === "Dive") {
- $index = intval($args[1]);
- if ($index >= 0 && $index < count($frogs)) {
- array_splice($frogs, $index, 1);
- }
- } else if ($command === "First") {
- $count = intval($args[1]);
- for ($i = 0; $i < count($frogs); $i++) {
- if ($count == 0) {
- break;
- }
- echo $frogs[$i] . " ";
- $count--;
- }
- echo PHP_EOL;
- } else if ($command === "Last") {
- $count = intval($args[1]);
- for ($i = count($frogs) - min($count,count($frogs)); $i < count($frogs); $i++) {
- echo $frogs[$i] . " ";
- }
- echo PHP_EOL;
- } else if ($command === "Jump") {
- $name = $args[1];
- $index = intval($args[2]);
- if ($index >= 0 && $index < count($frogs)) {
- array_splice($frogs, $index, 0, $name);
- }
- }
- $input = readline();
- }
Advertisement
Add Comment
Please, Sign In to add comment