emodev

Untitled

Mar 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: emotu
  5.  * Date: 012 12.3.2019 г.
  6.  * Time: 23:18
  7.  */
  8. $numberOfThePaintings = array_map('intval', explode(" ", readline()));
  9.  
  10. while (true) {
  11.     $length = count($numberOfThePaintings);
  12.     $command = readline();
  13.     if ($command == "END") {
  14.         break;
  15.     }
  16.     $line = explode(" ", $command);
  17.  
  18.  
  19.     if ($line[0] === "Change") {
  20.         for ($i = 0; $i < $length; $i++) {
  21.             if ($numberOfThePaintings[$i] == $line[1]) {
  22.                 $numberOfThePaintings[$i] = $line[2];
  23.                 break;
  24.             }
  25.         }
  26.  
  27.  
  28.     } elseif ($line[0] === "Hide") {
  29.         for ($i = 0; $i < $length; $i++) {
  30. //            Just equal sign here args1 Е стринг, а $array[$i] е инт и не съвпада тайпа
  31.             if ($numberOfThePaintings[$i] == $line[1]) {
  32.                 array_splice($numberOfThePaintings, $i, 1);
  33.             }
  34.  
  35.         }
  36.     } elseif ($line[0] === "Switch") {
  37.  
  38.         $index1 = array_search($line[1], $numberOfThePaintings);//5
  39.         $index2 = array_search($line[2], $numberOfThePaintings);//8
  40.         $indexxx = $index1; // кой е тоз
  41.         array_splice($numberOfThePaintings, $index1, 1, intval($line[2]));
  42.         array_splice($numberOfThePaintings, $index2, 1, intval($line[1]));
  43.  
  44.  
  45.     } elseif ($line[0] === "Insert") {
  46. //        $index = array_search($args[2], $array);
  47.         $index = intval($line[1]);
  48.         if ($index < $length - 1) {
  49.             array_splice($numberOfThePaintings, $index + 1, 0, intval($line[2]));
  50.  
  51.         }
  52.  
  53.     } elseif ($line[0] === "Reverse") {
  54.         $numberOfThePaintings = array_reverse($numberOfThePaintings);
  55.     }
  56. }
  57.  
  58.  
  59. echo implode(" ", $numberOfThePaintings);
Add Comment
Please, Sign In to add comment