Title Description
You must have played Minesweeper ! Now I'll give you some n×m Mine array , Please calculate the number of mines in the adjacent cells of each cell in each matrix , Each cell has at most 8 Adjacent cells . 0<
n,m< =100

（ Note that there should be a blank line between the two matrices , because oj The format of cannot be displayed here ）

input

The input contains several matrices , For each matrix , The first line contains two integers n and m, The number of rows and columns of the matrix . next n Each line contains m Characters . For safe area ‘.’ express , For use in mined areas ’*' express . When n=m=0 End of input .

Data scale and agreement
0< n,m< =100

output
For the second i Matrix , First print the serial number on a separate line ：“Field
#i:”, Next n In line , Read in ’.' Should be replaced by the number of mines around the location . Every two matrices of the output must be separated by a blank line .
sample input 4 4 *.. ... .*. .... 3 5 **.. .... .*... 0 0 sample output Field #1: *100 2210
1*10 1110 Field #2: **100 33200 1*100
Thinking of solving problems ：
Water topic !!! But I don't know why we should consider the boundary , I think it's right not to consider the boundary !

AC The code is as follows ：
#include <iostream> using namespace std; const int N = 110; int n, m; char g[N]
[N]; char a[N][N]; int main() { int count = 0; while (cin >> n >> m, n, m) {
count++; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> g[i][j
]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (g[i][j] ==
'*') a[i][j] = '*'; else if (g[i][j] == '.') { int cnt = 0; if ( i + 1 <= n && j
<= m && g[i + 1][j] == '*') cnt++; if (i + 1 <= n && j + 1 <= m && g[i + 1][j +
1] == '*') cnt++; if (i + 1 <= n && j - 1 >= 1 && g[i + 1][j - 1] == '*') cnt++;
if (i - 1 >= 1 && j <= m && g[i - 1][j] == '*') cnt++; if (i - 1 >= 1 && j + 1
<= m && g[i - 1][j + 1] == '*') cnt++; if (i - 1 >= 1 && j - 1 >= 1 && g[i - 1][
j- 1] == '*') cnt++; if (i <= n && j + 1 <= m && g[i][j + 1] == '*') cnt++; if (
i<= n && j - 1 >= 1 && g[i][j - 1] == '*') cnt++; a[i][j] = cnt + '0'; } } cout
<< "Field #" << count << ": " << endl; for (int i = 1; i <= n; i++) { for (int j
= 1; j <= m; j++) { cout << a[i][j]; } cout << endl; } cout << endl; } return 0;
}
I think it's right to ignore the boundary , But I don't know why ac no. , I can only take it 60 branch , The code is as follows ：
#include <iostream> using namespace std; const int N = 110; int n, m; char g[N]
[N]; char a[N][N]; int main() { int count = 0; while (cin >> n >> m, n, m) { for
(int i = 0; i <= n + 1; i++) for (int j = 0; j <= m + 1; j++) g[i][j] == '.';
count++; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> g[i][j
]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (g[i][j] ==
'*') a[i][j] = '*'; else if (g[i][j] == '.') { int cnt = 0; if (g[i + 1][j] ==
'*') cnt++; if (g[i + 1][j + 1] == '*') cnt++; if (g[i + 1][j - 1] == '*') cnt++
; if (g[i - 1][j] == '*') cnt++; if (g[i - 1][j + 1] == '*') cnt++; if (g[i - 1]
[j - 1] == '*') cnt++; if (g[i][j + 1] == '*') cnt++; if (g[i][j - 1] == '*')
cnt++; a[i][j] = cnt + '0'; } } cout << "Field #" << count << ": " << endl; for
(int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cout << a[i][j]; }
cout<< endl; } cout << endl; } return 0; }
Does anyone know why ??? Let me know the comments , Thank you !

Technology
Daily Recommendation
views 4