Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rows, columns = map(int, input().split())
- matrix = []
- start, boy_position = [], []
- pizza = False
- for row in range(rows):
- row_data = [char for char in input()]
- matrix.append(row_data)
- if "B" in row_data:
- start = (row, row_data.index("B"))
- boy_position = start
- matrix[boy_position[0]][boy_position[1]] = "."
- moves = {"up": (-1, 0), "down": (1, 0), "left": (0, -1), "right": (0, 1)}
- while True:
- move = input()
- row, col = moves[move]
- new_row = boy_position[0] + row
- new_col = boy_position[1] + col
- if 0 <= new_row < rows and 0 <= new_col < columns:
- next_cell = matrix[new_row][new_col]
- if next_cell == "*":
- continue
- boy_position = (new_row, new_col)
- if next_cell == "P":
- print("Pizza is collected. 10 minutes for delivery.")
- matrix[new_row][new_col] = "R"
- pizza = True
- elif next_cell == "A" and pizza:
- print("Pizza is delivered on time! Next order...")
- matrix[new_row][new_col] = "P"
- matrix[start[0]][start[1]] = "B"
- pizza = False
- break
- elif next_cell != "R" and next_cell != "A":
- matrix[new_row][new_col] = "."
- else:
- print("The delivery is late. Order is canceled.")
- matrix[start[0]][start[1]] = " "
- break
- [print(*row, sep="") for row in matrix]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement