You are tasked with counting the number of bomb squares adjacent to each empty square in a given H × W grid. The grid is represented as H strings, where each string consists of characters that denote either an empty square or a bomb.
Input Format
The first line of input contains two integers, H and W (1 ≤ H, W ≤ 1000), representing the height and width of the grid, respectively.
The next H lines each contain a string S_i (1 ≤ i ≤ H) of length W, representing the grid. Each character in the string is either:
. (an empty square)
# (a square containing a bomb)
Output Format
Output H strings, where each string is of the same length W. For each empty square (.), replace it with the number of bombs adjacent to that square. Bombs can be adjacent horizontally, vertically, or diagonally. The remaining bombs (#) should remain unchanged.
Example
Input
text
3 4
.#..
#..#
..#.
Output
text
1#1#
#322
..1#
Explanation
In the input grid:
The first string .#.. contains one bomb to the left of the empty square.
The second string #..# shows that the bombs are adjacent to empty squares below them.
The third string ..#. shows an empty square adjacent to one bomb directly below.
In the output, each . is replaced with a digit indicating the count of adjacent bombs, while # remains unchanged.
Solution
Please place the implementation of your solution in the /app/ directory.