You are given a grid of size H × W, represented by H strings, where each string consists of W characters. The characters in the grid can either be:
. (representing an empty square)
# (representing a square containing a bomb)
Your task is to determine the number of bomb squares that are adjacent to each empty square. An empty square is considered "adjacent" if it is directly horizontal, vertical, or diagonal to it. Each empty square has at most eight adjacent squares.
Input Format
The first line contains two integers, H and W (1 ≤ H, W ≤ 100), representing the number of rows and columns in the grid, respectively.
The next H lines each contain a string of length W, consisting of characters . and #.
Output Format
You need to output H strings, where each . is replaced with a digit representing the number of adjacent bomb squares, and # remains unchanged.
Example
Input
text
3 3
.#.
#..
...
Output
text
1#1
1#1
000
Explanation
The first string has one bomb directly below the empty square at (1,2) and one bomb to the left at (2,1).
The second string has one bomb directly above at (1,1).
The third string has no bombs adjacent to any empty squares.
Implementation
You should implement your solution in the /app/ directory.
Make sure to follow the input/output format strictly, and handle different cases to ensure that the program works for all valid inputs.