Advertisement
Davitkova

delivery_boy

Oct 5th, 2024 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. rows, columns = map(int, input().split())
  2.  
  3. matrix = []
  4. start, boy_position = [], []
  5. pizza = False
  6.  
  7. for row in range(rows):
  8.  
  9.     row_data = [char for char in input()]
  10.     matrix.append(row_data)
  11.    
  12.     if "B" in row_data:
  13.         start = (row, row_data.index("B"))
  14.         boy_position = start
  15.         matrix[boy_position[0]][boy_position[1]] = "."
  16.  
  17. moves = {"up": (-1, 0), "down": (1, 0), "left": (0, -1), "right": (0, 1)}
  18.  
  19. while True:
  20.    
  21.     move = input()
  22.     row, col = moves[move]
  23.     new_row = boy_position[0] + row
  24.     new_col = boy_position[1] + col
  25.    
  26.     if 0 <= new_row < rows and 0 <= new_col < columns:
  27.        
  28.         next_cell = matrix[new_row][new_col]
  29.  
  30.         if next_cell == "*":
  31.             continue
  32.  
  33.         boy_position = (new_row, new_col)
  34.  
  35.         if next_cell == "P":
  36.            
  37.             print("Pizza is collected. 10 minutes for delivery.")
  38.             matrix[new_row][new_col] = "R"
  39.             pizza = True
  40.            
  41.         elif next_cell == "A" and pizza:
  42.            
  43.             print("Pizza is delivered on time! Next order...")
  44.             matrix[new_row][new_col] = "P"
  45.             matrix[start[0]][start[1]] = "B"
  46.             pizza = False
  47.             break
  48.            
  49.         elif next_cell != "R" and next_cell != "A":
  50.            
  51.             matrix[new_row][new_col] = "."
  52.  
  53.     else:
  54.         print("The delivery is late. Order is canceled.")
  55.         matrix[start[0]][start[1]] = " "
  56.         break
  57.  
  58. [print(*row, sep="") for row in matrix]
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement