You are given a grid of height ( H ) and width ( W ), represented by ( H ) strings ( S_1, S_2, \ldots, S_H ). Each string ( S_i ) describes the squares in the ( i )-th row. The grid is composed of two types of squares:
. (dot), representing an empty square
# (hash), representing a square containing a bomb
Your task is to count the number of bomb squares (#) that are adjacent (horizontally, vertically, or diagonally) to each empty square (.). For each empty square, you will replace the . with a digit that indicates the count of adjacent bomb squares.
Input Format
The first line contains two integers ( H ) and ( W ) (1 ≤ ( H ), ( W ) ≤ 100), representing the height and width of the grid.
The next ( H ) lines each contain a string of length ( W ), which consists of characters . and #.
Output Format
Print ( H ) strings of length ( W ). Each . should be replaced by a digit (0 to 8) indicating the number of adjacent bomb squares. The bomb squares (#) should remain unchanged.
Example
Input
text
3 3
.#.
.#.
###
Output
text
1#1
1#1
###
Explanation
The empty squares adjacent to the first . have 1 bomb square each.
The second and third rows contain only bomb squares, so they remain unchanged.
Notes
You can consider a square adjacent if it is one of the eight surrounding squares (above, below, left, right, and the four diagonals).
Handle cases where the indices may go out of bounds by simply ignoring those directions.
Solution Directory
Please place your solution in the /app/ directory.