-
Notifications
You must be signed in to change notification settings - Fork 0
/
10189.cpp
51 lines (43 loc) · 1.26 KB
/
10189.cpp
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
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll p[102][102];
string board[102];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,m, cse = 1;
while(cin >> n >> m && n){
if(cse != 1 && n != 0) cout << "\n";
for(ll i = 0; i < n; i++){
cin >> board[i];
for(ll j = 0; j < m; j++){
p[i][j] = 0;
}
}
for(ll i = 0; i < n; i++){
for(ll j = 0; j < m; j++){
if(board[i][j]=='*'){
ll x[8] = {-1,-1,-1,0,1,1,1,0};
ll y[8] = {-1,0,1,1,1,0,-1,-1};
for(ll k = 0; k < 8; k++){
ll imove = i + x[k]; ll jmove = j + y[k];
bool a = imove >= 0 && imove < n;
bool b = jmove >= 0 && jmove < m;
if(a && b) ++p[imove][jmove];
}
}
}
}
cout << "Field #" << cse << ":\n";
for(ll i = 0; i < n; i++){
for(ll j = 0; j < m; j++){
if(board[i][j] == '*') cout << '*';
else cout << p[i][j];
}
cout << "\n";
}
++cse;
}
return 0;
}