Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: emotu
- * Date: 012 12.3.2019 г.
- * Time: 23:18
- */
- $numberOfThePaintings = array_map('intval', explode(" ", readline()));
- while (true) {
- $length = count($numberOfThePaintings);
- $command = readline();
- if ($command == "END") {
- break;
- }
- $line = explode(" ", $command);
- if ($line[0] === "Change") {
- for ($i = 0; $i < $length; $i++) {
- if ($numberOfThePaintings[$i] == $line[1]) {
- $numberOfThePaintings[$i] = $line[2];
- break;
- }
- }
- } elseif ($line[0] === "Hide") {
- for ($i = 0; $i < $length; $i++) {
- // Just equal sign here args1 Е стринг, а $array[$i] е инт и не съвпада тайпа
- if ($numberOfThePaintings[$i] == $line[1]) {
- array_splice($numberOfThePaintings, $i, 1);
- }
- }
- } elseif ($line[0] === "Switch") {
- $index1 = array_search($line[1], $numberOfThePaintings);//5
- $index2 = array_search($line[2], $numberOfThePaintings);//8
- $indexxx = $index1; // кой е тоз
- array_splice($numberOfThePaintings, $index1, 1, intval($line[2]));
- array_splice($numberOfThePaintings, $index2, 1, intval($line[1]));
- } elseif ($line[0] === "Insert") {
- // $index = array_search($args[2], $array);
- $index = intval($line[1]);
- if ($index < $length - 1) {
- array_splice($numberOfThePaintings, $index + 1, 0, intval($line[2]));
- }
- } elseif ($line[0] === "Reverse") {
- $numberOfThePaintings = array_reverse($numberOfThePaintings);
- }
- }
- echo implode(" ", $numberOfThePaintings);
Add Comment
Please, Sign In to add comment