-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMine Sweeper.cpp
57 lines (48 loc) · 1.09 KB
/
Mine Sweeper.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
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
std::cin.sync_with_stdio(0);
std::cin.tie(0);
int n,height;
string s;
char c,mine[110][110],ans[110][110];
cin>>n;
for(int cs=0;cs<n;cs++){
if(cs) cout << endl;
bool dead=false;
memset(mine,0,sizeof(mine));
memset(ans,'.',sizeof(ans));
cin>>height;
for(int i=1;i<=height;i++){
for(int j=1;j<=height;j++){
cin>>c;
mine[i][j]=c;
}
}
for(int i=1;i<=height;i++){
for(int j=1;j<=height;j++){
cin>>c;
if(c=='x'){
int cnt=0;
if(mine[i][j]=='*') continue;
if(mine[i-1][j-1]=='*') cnt++;
if(mine[i-1][j]=='*') cnt++;
if(mine[i-1][j+1]=='*') cnt++;
if(mine[i][j-1]=='*') cnt++;
if(mine[i][j+1]=='*') cnt++;
if(mine[i+1][j-1]=='*') cnt++;
if(mine[i+1][j]=='*') cnt++;
if(mine[i+1][j+1]=='*') cnt++;
ans[i][j]=cnt+'0';
}
}
}
for(int i=1;i<=height;i++){
for(int j=1;j<=height;j++){
cout << ans[i][j];
}
cout << endl;
}
}
return 0;
}