Advertisement
DiYane

Battle ships

Sep 25th, 2023
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. rows = int(input())
  2. ships_list = []
  3.  
  4. for current_row in range(rows):
  5.     ships = input().split(' ')
  6.     ships_list.append(ships)
  7. attacked_squares = input().split(' ')
  8.  
  9. destroyed_counter = 0
  10. for attack in attacked_squares:
  11.     current_attack = attack.split('-')
  12.     row = int(current_attack[0])
  13.     col = int(current_attack[1])
  14.  
  15.     current_ship = ships_list[row]
  16.     curr_ship = int(current_ship[col])
  17.  
  18.     if curr_ship > 0:
  19.         curr_ship -= 1
  20.         if curr_ship == 0:
  21.             destroyed_counter += 1
  22.  
  23.     current_ship[col] = str(curr_ship)
  24.     ships_list[row] = current_ship
  25.  
  26. print(destroyed_counter)
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement