Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $array = array_map('intval', explode(' ', readline()));
- $input = readline();
- while (true) {
- $commands = explode(' ', $input);
- if ($commands[0] === 'Delete') {
- for ($i = 0; $i < count($array); $i++) {
- if (intval($commands[1]) === $array[$i]) {
- array_splice($array, $i, 1);
- $i--;
- }
- }
- } elseif ($commands[0] === 'Insert') {
- array_splice($array, intval($commands[2]), 0, intval($commands[1]));
- } elseif ($commands[0] === 'Odd') {
- foreach ($array as $item) {
- if ($item % 2 === 1) {
- echo $item . " ";
- }
- }
- break;
- } elseif ($commands[0] === 'Even') {
- foreach ($array as $item) {
- if ($item % 2 === 0) {
- echo $item . " ";
- }
- }
- break;
- }
- $input = readline();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement