Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- text = input()
- size = int(input())
- matrix = []
- player_row, player_col = None, None
- for row in range(size):
- matrix.append(list(input()))
- for col in range(size):
- if matrix[row][col] == "P":
- player_row, player_col = row, col
- break
- m = int(input())
- for _ in range(m):
- next_row, next_col = player_row, player_col
- command = input()
- 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 next_row < 0 or next_col < 0 or next_row >= size or next_col >= size:
- text = text[:-1]
- continue
- if matrix[next_row][next_col] != '-':
- text = text + str(matrix[next_row][next_col])
- matrix[player_row][player_col] = '-'
- matrix[next_row][next_col] = 'P'
- player_row, player_col = next_row, next_col
- print(text)
- for row in matrix:
- print(*row, sep='')
Advertisement
Add Comment
Please, Sign In to add comment