Guest User

Battleships

a guest
Feb 2nd, 2021
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. rows_count = int(input())
  2. coord_list = []
  3.  
  4. while rows_count > 0:
  5.     coord_list.append(input().split())
  6.     rows_count -= 1
  7.  
  8. coord_list = [[int(x) for x in coord_list[0]],
  9.               [int(x) for x in coord_list[1]],
  10.               [int(x) for x in coord_list[2]]]
  11.  
  12. # the location description - row/column
  13.  
  14. attacks_list = input().split()
  15. ships_destroyed = 0
  16.  
  17. for element in attacks_list:
  18.     coord1, coord2 = element.split('-')
  19.     coord1 = int(coord1)
  20.     coord2 = int(coord2)
  21.     if coord_list[coord1][coord2] > 0:
  22.         coord_list[coord1][coord2] -= 1
  23.         if coord_list[coord1][coord2] == 0:
  24.             ships_destroyed += 1
  25.  
  26. print(ships_destroyed)
Advertisement
Add Comment
Please, Sign In to add comment