SHARE
TWEET

Untitled

a guest Aug 24th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $word = explode(" ", readline());
  3. $input = readline();
  4. while ($input != "Stop") {
  5.     $comand = explode(" ", $input);
  6.     switch ($comand[0]) {
  7.         case"Delete":
  8.             $index = $comand[1] + 1;
  9.             if ($index >= 0 && $index <= count($word)) {
  10.                 array_splice($word, $index, 1);
  11.             }
  12.             break;
  13.         case"Swap":
  14.             $word1 = $comand[1];
  15.             $word2 = $comand[2];
  16.             if (in_array($word1, $word) && in_array($word2, $word)) {
  17.                 $temp = $word1;
  18.                 $index1 = array_search($word1, $word);
  19.                 $index2 = array_search($word2, $word);
  20.                 array_splice($word, $index1, 1, $word2);
  21.                 array_splice($word, $index2, 1, $temp);
  22.  
  23.             }
  24.             break;
  25.         case"Put":
  26.             $element = $comand[1];
  27.             $index = $comand[2];
  28.             if ($index >= 0 && $index <= count($word)+1) {
  29.                 array_splice($word, $index - 1, 0, $element);
  30.             }
  31.             break;
  32.         case"Sort":
  33.             rsort($word);
  34.             break;
  35.         case"Replace":
  36.             $word1 = $comand[1];
  37.             $word2 = $comand[2];
  38.             if (in_array($word2, $word)) {
  39.                 $index = array_search($word2, $word);
  40.                 array_splice($word, $index, 1, $word1);
  41.             }
  42.             break;
  43.     }
  44.     $input = readline();
  45. }
  46. echo implode(" ", $word);
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