Advertisement
Guest User

Untitled

a guest
Jul 28th, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2. $arr = explode(" ", readline());
  3. $input = readline();
  4. while ($input !== "end") {
  5. $args = explode(" ", $input);
  6. $comand = $args[0];
  7. switch ($comand) {
  8. case"swap":
  9. $index1 =$args[1];
  10. $index2 = $args[2];
  11. if (isset($arr[$index1])&& isset($arr[$index2])) {
  12. $temp = $arr[$index1];
  13. $arr[$index1] = $arr[$index2];
  14. $arr[$index2] = $temp;
  15. }
  16. break;
  17. case"multiply":
  18. $index1 = $args[1];
  19. $index2 = $args[2];
  20. if (isset($arr[$index1])&& isset($arr[$index2])) {
  21. $arr[$index1] = $arr[$index1] * $arr[$index2];
  22. }
  23. break;
  24. case"decrease":
  25. $index1 = $args[1];
  26. for ($i = 0; $i < count($arr); $i++) {
  27. $arr[$i] = $arr[$i] - $index1;
  28. }
  29. break;
  30. case"increase":
  31. $index1 = $args[1];
  32. for ($i = 0; $i < count($arr); $i++) {
  33. $arr[$i] += $index1;
  34. }
  35. break;
  36. case"remove":
  37. $index1 = $args[1];
  38. if (isset($arr[$index1])) {
  39. array_splice($arr, $index1, 1);
  40. }
  41. break;
  42. }
  43. $input = readline();
  44. }
  45. echo implode(", ", $arr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement