#P2670. Minesweeper Adjacent Mine Count
Minesweeper Adjacent Mine Count
Minesweeper Adjacent Mine Count
This is a classic Minesweeper problem. You are given an \( n \)-row by \( m \)-column grid where some cells contain mines (denoted by '*') and others are empty (denoted by a dot '.'). A safe cell (one that does not contain a mine) displays a number indicating how many mines are in its 8 adjacent neighbors (vertically, horizontally, and diagonally). Your task is to compute the number of adjacent mines for each safe cell, while leaving the mine cells unchanged.
Note: The adjacent cells of a cell located at \( (i,j) \) include those at \( (i-1,j-1) \), \( (i-1,j) \), \( (i-1,j+1) \), \( (i,j-1) \), \( (i,j+1) \), \( (i+1,j-1) \), \( (i+1,j) \), and \( (i+1,j+1) \) if they exist.
inputFormat
The first line contains two integers \( n \) and \( m \) representing the number of rows and columns, respectively. The following \( n \) lines each contain a string of length \( m \). Each character is either '*' (denoting a mine) or '.' (denoting a safe cell).
outputFormat
Output \( n \) lines corresponding to the grid after processing. For each cell, if it contains a mine ('*'), output '*' unchanged. Otherwise, output the number of mines in the adjacent cells. There should be no spaces between the characters in a line.
sample
3 3
*..
...
..*
*10
121
01*
</p>