Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $n = intval(readline());
- $arr = array_map('intval', explode(' ', readline()));
- $cells = [];
- for ($i = 0; $i < $n; $i++) {
- $cells[$i] = 0;
- }
- for ($i = 0; $i < count($arr); $i++) {
- if (array_key_exists($arr[$i], $cells)) {
- $cells[$arr[$i]] = 1;
- }
- }
- $command = readline();
- while ($command != 'end') {
- $arr = explode(' ', $command);
- $position = intval($arr[0]);
- $direction = $arr[1];
- $shift = intval($arr[2]);
- if (array_key_exists($position, $cells) && $cells[$position] == 1) {
- $cells[$position] = 0;
- if ($direction == 'left') {
- $shift = -$shift;
- }
- for ($i = $position + $shift; array_key_exists($i, $cells); $i += $shift) {
- if ($cells[$i] == 0) {
- $cells[$i] = 1;
- break;
- }
- }
- }
- $command = readline();
- }
- echo implode(' ', $cells);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement