Johnny and Roy do not go to class; they prefer to play wars of ships. As now they want to play it in a computer, they have asked Steffy to write them a program. Unfortunately, Steffy is studying NP-complete problems, so she has passed you the order.
According to Johnny and Roy rules, the game is played in a rectangular grid. First, Johnny sets the ships in the grid (obviously, Roy can not see where Johnny sets the ships). After that, Roy shoots, trying to sink the ships. When in the coordinate that Roy says there is not any ship, Johnny says “water’’. When a ship is hit but it is not sunk, Johnny says “hit’’. If with this shoot all the positions of the ship have been hit, Johnny says “sunk’’, but in the future he will say “water’’ for any of these positions.
Your task is to write a program that reads a grid of ships and a sequence of shoots. For each shoot, the program must print “water”, “hit” or “sunk” as explained in the rules. Moreover, the program has to print the final state of the fleet.
The number of rows and the number of columns of the grid are given first; and are fulfilled. After that, there are lines with characters each one. A dot indicates an empty position, a ‘|S|’ a ship position. Ships are placed horizontally, and they can not touch themselves nor the border of the grid. Finally, a non empty sequence of shoots is given (all of them inside the grid), indicating the row with a lowercase letter and the column with a natural number. The position on the top and left is a |0|.
Your program must print each shoot followed by its result (“|water|”, “|hit|” or “|sunk|”) as it is shown in the instances. After that, the program must print an empty line and then print the state of the grid. Print a character ‘|T|’ for the positions which are hit but not sink.
Author: Unknown
Translator: Carlos Molina
Generation: 2026-01-25T12:02:39.805Z
© Jutge.org, 2006–2026.
https://jutge.org