#P361. 【例62.3】 地雷数计算

【例62.3】 地雷数计算

Description

Minesweeper is a classic single-player game. Its essence lies in determining whether unopened cells contain mines based on the numbers shown in opened cells, which indicate the count of mines in surrounding cells.
Given the mine distribution in an n×mn \times m minefield, calculate the number of surrounding mines for each non-mine cell.
Note: Each cell has eight surrounding cells: up, down, left, right, upper-left, upper-right, lower-left, and lower-right.

Input Format

First line contains two integers nn and mm, representing the number of rows and columns in the minefield (1n1001 \le n \le 100, 1m1001 \le m \le 100).
Next nn lines, each containing mm characters, where '*' represents a mine and '??' represents a non-mine cell. There are no separators between characters.

Output Format

Output nn lines, each containing mm characters, describing the entire minefield. If a cell contains a mine, represent it with '*', otherwise represent it with the number of surrounding mines. There are no separators between characters.

Sample

3 3
*??
???
?*?
*10
221
1*1