#P2670. [NOIP 2015 普及组] 扫雷游戏

[NOIP 2015 普及组] 扫雷游戏

Description

Minesweeper is a classic single-player mini game. In an nn-row by mm-column minefield, some cells contain mines (called mine cells), and the other cells do not (called non-mine cells). When the player reveals a non-mine cell, the cell shows a number indicating how many of its neighboring cells are mine cells. The goal is to find all non-mine cells without revealing any mine cell.

Given the distribution of mines in an nn-row by mm-column minefield, compute for every non-mine cell the number of neighboring mine cells.

Note: The neighboring cells of a cell include the eight directly adjacent cells in the up, down, left, right, upper-left, upper-right, lower-left, and lower-right directions.

Input Format

The first line contains two integers nn and mm separated by a space, representing the number of rows and columns of the minefield, respectively.

Then follow nn lines, each with mm characters, describing the distribution of mines in the minefield. The character *\texttt{*} indicates a mine cell, and the character ?\texttt{?} indicates a non-mine cell. There are no delimiters between adjacent characters.

Output Format

The output contains nn lines, each with mm characters, describing the entire minefield. Use *\texttt{*} for mine cells, and use the number of neighboring mines for non-mine cells. There are no delimiters between adjacent characters.

3 3
*??
???
?*?

*10
221
1*1
2 3
?*?
*??
2*1
*21

Hint

For 100%100\% of the testdata, 1n1001 \le n \le 100, 1m1001 \le m \le 100.

Translated by ChatGPT 5