← 返回 uber 的题目列表Minesweeper Board Update
类型:online_judge
Given a Minesweeper board board and one click position (clickRow, clickCol), return the board after applying the click.
Cell meanings:
M: an unrevealed mine.
E: an unrevealed empty cell.
B: a revealed blank cell with no adjacent mines.
1 to 8: a revealed cell whose value is the number of adjacent mines.
X: a mine that was clicked and exploded.
Update rules:
If the clicked cell is M, change it to X and stop.
If the clicked cell is E, count mines in its eight neighboring cells:
If the count is positive, replace it with that digit.
Otherwise, replace it with B and recursively reveal all adjacent unrevealed E cells.
Cells not revealed by this click must remain unchanged.
Input Format
m n
board[0]
board[1]
...
board[m-1]
clickRow clickCol
Each board row is a string of length n.
Output Format
Print the updated board, one row per line.
Constraints
1 <= m, n <= 50
Each input board cell is either M or E
0 <= clickRow < m, 0 <= clickCol < n
Example
Input
4 5
EEEEE
EEMEE
EEEEE
EEEEE
3 0
Output
B1E1B
B1M1B
B111B
BBBBB
Example
Input
4 5
EEEEE
EEMEE
EEEEE
EEEEE
3 0
Output
B1E1B
B1M1B
B111B
BBBBB