-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path984B. Minesweeper.cpp
56 lines (44 loc) · 1.06 KB
/
984B. Minesweeper.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
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[101][101];
int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[] = {1, 1, 0, -1, -1, -1, 0, 1};
int main() {
cin >> n >> m;
for(int i = 0; i < n; ++i)
scanf("%s", s[i]);
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
if(s[i][j] == '.') {
for(int k = 0, ni, nj; k < 8; ++k) {
ni = i + dx[k];
nj = j + dy[k];
if(ni < 0 || ni >= n || nj < 0 || nj >= m)
continue;
if(s[ni][nj] == '*') {
cout << "NO" << endl;
return 0;
}
}
} else if(isdigit(s[i][j])) {
int cnt = 0;
for(int k = 0, ni, nj; k < 8; ++k) {
ni = i + dx[k];
nj = j + dy[k];
if(ni < 0 || ni >= n || nj < 0 || nj >= m)
continue;
if(s[ni][nj] == '*') {
++cnt;
}
}
if(cnt != (s[i][j] - '0')) {
cout << "NO" << endl;
return 0;
}
}
}
}
cout << "YES" << endl;
return 0;
}