Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_inside(r, c, size_):
- if 0 <= r < size_ and 0 <= c < size_:
- return True
- return False
- string_line = input()
- size = int(input())
- field = []
- player_row, player_col = None, None
- for row in range(size):
- field.append(list(input()))
- if "P" in field[row]:
- player_row, player_col = row, field[row].index('P')
- num = int(input())
- for _ in range(num):
- command = input()
- next_row, next_col = player_row, player_col
- if command == "up":
- next_row -= 1
- elif command == "down":
- next_row += 1
- elif command == "left":
- next_col -= 1
- elif command == "right":
- next_col += 1
- if not is_inside(next_row, next_col, size):
- string_line = string_line[:-1]
- continue
- field[player_row][player_col] = '-'
- if field[next_row][next_col] != '-':
- string_line += field[next_row][next_col]
- field[next_row][next_col] = 'P'
- player_row, player_col = next_row, next_col
- print(string_line)
- for row in field:
- print(*row, sep='')
Advertisement
Add Comment
Please, Sign In to add comment