1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false), cin.tie(nullptr) using namespace std;
int b4i[] = {0, 1, 0, -1, -1, -1, 1, 1}, b4j[] = {1, 0, -1, 0, -1, 1, -1, 1}; int main(){ fastio; int n, m, mines[101][101], c = 0; char mp[101][101]; while(cin >> n){ cin >> m; if(n == 0 && m == 0) break; memset(mines, 0, sizeof(mines)); for(int i = 0; i < n; ++i){ for(int j = 0; j < m; ++j){ cin >> mp[i][j]; if(mp[i][j] == '*') mines[i][j] = 9; } } for(int i = 0; i < n; ++i){ for(int j = 0; j < m; ++j){ if(mp[i][j] == '*'){ for(int dir = 0; dir < 8; ++dir){ int di = i + b4i[dir], dj = j + b4j[dir]; if(di >= 0 && di < n && dj >= 0 && dj < m){ if(mines[di][dj] != 9){ ++mines[di][dj]; } } } } } } cout << "Field #" << ++c << ":\n"; for(int i = 0; i < n; ++i){ for(int j = 0; j < m; ++j){ if(mines[i][j] == 9) cout << "*"; else cout << mines[i][j]; } cout << "\n"; } cout << "\n"; } }
|