-
Notifications
You must be signed in to change notification settings - Fork 0
/
10279Minesweeper.cpp
99 lines (98 loc) · 1.71 KB
/
10279Minesweeper.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
freopen("in2.txt","r",stdin);
int i,j;
int tCase,n;
bool touched,newLine=false;
char board1[10][10],board2[10][10],board3[10][10];
scanf("%d",&tCase);
while(tCase--){
scanf("%d",&n);
if(newLine)printf("\n");
memset(board3,'.',sizeof(board3));
for(i=0;i<n;i++){
getchar();
for(j=0;j<n;j++){
scanf("%c",&board1[i][j]);
}
}
for(i=0;i<n;i++){
getchar();
for(j=0;j<n;j++){
scanf("%c",&board2[i][j]);
}
}
touched=false;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(board2[i][j]=='x'){
board3[i][j]='0';
if(board1[i][j]=='*'){
touched=true;
}else{
if(j+1<n){
if(board1[i][j+1]=='*'){
board3[i][j]++;
}
}
if(i+1<n && j+1<n){
if(board1[i+1][j+1]=='*'){
board3[i][j]++;
}
}
if(i+1<n){
if(board1[i+1][j]=='*'){
board3[i][j]++;
}
}
if(i+1<n && j-1>=0){
if(board1[i+1][j-1]=='*'){
board3[i][j]++;
}
}
if(j-1>=0){
if(board1[i][j-1]=='*'){
board3[i][j]++;
}
}
if(i-1>=0 && j-1>=0){
if(board1[i-1][j-1]=='*'){
board3[i][j]++;
}
}
if(i-1>=0){
if(board1[i-1][j]=='*'){
board3[i][j]++;
}
}
if(i-1>=0 && j+1<n){
if(board1[i-1][j+1]=='*'){
board3[i][j]++;
}
}
}
}
}
}
if(touched){
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(board1[i][j]=='*'){
board3[i][j]='*';
}
}
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%c",board3[i][j]);
}
printf("\n");
}
newLine=true;
}
return 0;
}