Advertisement
mmishanchyk

2 zadacha

Jun 28th, 2021
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. def in_range(row, col, size):
  2.     if 0 <= row < 5 and 0 <= col < 5:
  3.         return True
  4.     return False
  5.  
  6.  
  7. matrix = []
  8.  
  9. for row in range(5):
  10.     matrix.append([el for el in input().split()])
  11.  
  12. for row in range(5):
  13.     for col in range(5):
  14.         if matrix[row][col] == "A":
  15.             start_row = row
  16.             start_col = col
  17.  
  18. counter = 0
  19.  
  20. for row in range(5):
  21.     for col in range(5):
  22.         if matrix[row][col] == "x":
  23.             counter += 1
  24.  
  25. directions = {
  26.     "up": [-1, 0],
  27.     "down": [1, 0],
  28.     "left": [0, -1],
  29.     "right": [0, 1]}
  30.  
  31. n = int(input())
  32. target = []
  33.  
  34. for i in range(n):
  35.     commands = input().split()
  36.     command = commands[0]
  37.     direction = commands[1]
  38.  
  39.     if command == "shoot":
  40.         next_row = start_row + directions[direction][0]
  41.         next_col = start_col + directions[direction][1]
  42.         if in_range(next_row, next_col, 5):
  43.             if matrix[next_row][next_col] == "x":
  44.                 target.append([next_row, next_col])
  45.                 matrix[next_row][next_col] = "."
  46.  
  47.     elif command == "move":
  48.         step = int(commands[2])
  49.  
  50.         next_row = start_row + (directions[direction][0]) * step
  51.         next_col = start_col + (directions[direction][1]) * step
  52.         if in_range(next_row, next_col, 5):
  53.             if matrix[next_row][next_col] == ".":
  54.                 matrix[next_row][next_col] = "A"
  55.         start_row += (directions[direction][0]) * step
  56.         start_col += (directions[direction][1]) * step
  57.  
  58.  
  59. if len(target) == counter:
  60.     print(f"Training completed! All {counter} targets hit.")
  61.     [print(el) for el in target]
  62. else:
  63.     print(f"Training not completed! {counter - len(target)} targets left.")
  64.     [print(el) for el in target]
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement