Advertisement
go6odn28

2_space_mission

Feb 11th, 2025
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. MATRIX_SIZE = int(input())
  2.  
  3. matrix = []
  4. spaceship = []
  5.  
  6. for r in range(MATRIX_SIZE):
  7.     matrix.append(input().split())
  8.     for c in range(MATRIX_SIZE):
  9.         if matrix[r][c] == 'S':
  10.             spaceship = [r, c]
  11.             matrix[r][c] = '.'
  12.  
  13. is_lost = False
  14. is_accomplished = False
  15. units = 100
  16. moves = {
  17.     "up": (-1, 0),
  18.     "down": (1, 0),
  19.     "left": (0, -1),
  20.     "right": (0, 1)
  21. }
  22.  
  23. while units >= 5:
  24.  
  25.     command = input()
  26.     units -= 5
  27.  
  28.     current_row = spaceship[0]
  29.     current_col = spaceship[1]
  30.  
  31.     move = moves[command]
  32.     new_row = spaceship[0] + move[0]
  33.     new_col = spaceship[1] + move[1]
  34.  
  35.     if 0 <= new_row < MATRIX_SIZE and 0 <= new_col < MATRIX_SIZE:
  36.  
  37.         if matrix[new_row][new_col] == 'P':
  38.             # if matrix[current_row][current_col] != 'R':
  39.             #     matrix[current_row][current_col] = '.'
  40.             is_accomplished = True
  41.             print(f"Mission accomplished! The spaceship reached Planet B with {units} resources left.")
  42.             break
  43.         elif matrix[new_row][new_col] == 'M':
  44.             # matrix[new_row][new_col] = '.'
  45.             units -= 5
  46.         elif matrix[new_row][new_col] == 'R':
  47.             units = min(100, units + 10)
  48.             spaceship = [new_row, new_col]
  49.             continue
  50.  
  51.         # if units < 5:
  52.         #     spaceship = [new_row, new_col]
  53.         #     break
  54.  
  55.         spaceship = [new_row, new_col]
  56.         if matrix[new_row][new_col] != 'R':
  57.             matrix[new_row][new_col] = '.'
  58.     else:
  59.         is_lost = True
  60.         break
  61.  
  62. if units < 5 and not is_accomplished and not is_lost:  # Добавих проверката - not is_lost
  63.     r, c = spaceship
  64.     matrix[r][c] = 'S'
  65.     print(f"Mission failed! The spaceship was stranded in space.")
  66. elif is_lost and not is_accomplished:
  67.     r, c = spaceship
  68.     matrix[r][c] = 'S'
  69.     print(f"Mission failed! The spaceship was lost in space.")
  70.  
  71. for r in matrix:
  72.     print(" ".join(r))
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement