Advertisement
pacho_the_python

Untitled

Dec 14th, 2022
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. size = int(input())
  2.  
  3. car_number = input()
  4.  
  5. matrix = []
  6.  
  7. for i in range(size):
  8.     row = input().split(" ")
  9.     matrix.append(row)
  10.  
  11.  
  12. def next_car_position(x, y, direction):
  13.     if direction == 'left':
  14.         y =y - 1
  15.         return x, y
  16.     elif direction == 'right':
  17.         y = y + 1
  18.         return x, y
  19.     elif direction == "up":
  20.         x = x - 1
  21.         return x, y
  22.     elif direction == "down":
  23.         x = x + 1
  24.         return x, y
  25.  
  26.  
  27. def get_after_tunel_position():
  28.     for j in range(len(matrix)):
  29.         for k in range(len(matrix[j])):
  30.             if matrix[j][k] == "T":
  31.                 return j, k
  32.  
  33.  
  34. row = 0
  35. col = 0
  36.  
  37. command = input()
  38. distance = 0
  39.  
  40.  
  41. while True:
  42.  
  43.     if command == "End":
  44.         matrix[row][col] = 'C'
  45.         print(f'Racing car {car_number} DNF.')
  46.         break
  47.  
  48.     car_row, car_col = next_car_position(row, col, command)
  49.  
  50.     if matrix[car_row][car_col] == 'F':
  51.         distance += 10
  52.         matrix[car_row][car_col] = 'C'
  53.         print(f'Racing car {car_number} finished the stage!')
  54.         break
  55.  
  56.     if matrix[car_row][car_col] == ".":
  57.         distance += 10
  58.         row, col = car_row, car_col
  59.  
  60.     elif matrix[car_row][car_col] == "T":
  61.         matrix[car_row][car_col] = "."
  62.  
  63.         car_row, car_col = get_after_tunel_position()
  64.         distance += 30
  65.         matrix[car_row][car_col] = "."
  66.         row, col = car_row, car_col
  67.  
  68.     command = input()
  69.  
  70. print(f'Distance covered {distance} km.')
  71.  
  72. for i in matrix:
  73.     print(''.join(i))
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement