Advertisement
GalinaKG

Battle Ships

Jun 22nd, 2022
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. def attack(field, square):
  2.     ships_destroyed = 0
  3.     for att in square:
  4.         turn = att.split('-')
  5.         row = int(turn[0])
  6.         column = int(turn[1])
  7.  
  8.         if field[row][column] > 0:
  9.             field[row][column] -= 1
  10.             if field[row][column] == 0:
  11.                 ships_destroyed += 1
  12.  
  13.     return ships_destroyed
  14.  
  15.  
  16. rows = int(input())
  17. fields = []
  18. for _ in range(rows):
  19.     temp_field = input().split()
  20.     fields.append(list(map(int, ''.join(temp_field))))
  21. square_attacked = input().split()
  22. print(attack(fields, square_attacked))
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement