You are given a grid of dimensions ( H \times W ). The grid is represented by ( H ) strings ( S_1, S_2, \ldots, S_H ). Each string consists of characters where:
. represents an empty square
# represents a square containing a bomb
Your task is to determine how many bomb squares are horizontally, vertically, or diagonally adjacent to each empty square. For each empty square represented by ., you will replace it with a digit that indicates the number of bomb squares adjacent to it.
Note: Each empty square can have up to eight adjacent squares.
Input Format
The first line contains two integers ( H ) and ( W ) (1 ≤ ( H, W ) ≤ 100), representing the height and width of the grid, respectively.
The following ( H ) lines each contain a string ( S_i ) (1 ≤ ( |S_i| \leq W )), which consists of characters . and #.
Output Format
Print ( H ) lines containing the transformed strings, where each . is replaced by a digit indicating the number of adjacent bomb squares. The # characters should remain unchanged.
Examples
Example 1
Input:
text
3 3
.#.
#..
..#
Output:
text
1#1
#22
11#
Example 2
Input:
text
5 5
..#..
.#.#.
..#..
.#...
.....
Output:
text
11#21
1#2#1
11#21
1#111
.....
Constraints
( 1 \leq H, W \leq 100 )
All strings are of length ( W )
Solution
The solution should be implemented in the /app directory. Please ensure that your code adheres to the input/output format specified above.