-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path825B. Five-In-a-Row.cpp
63 lines (53 loc) · 1.07 KB
/
825B. Five-In-a-Row.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
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
char g[11][11];
bool check() {
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j) {
int cnt = 0;
while(j < 10 && g[i][j] == 'X')
++cnt, ++j;
if(cnt >= 5)
return true;
}
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j) {
int cnt = 0;
while(j < 10 && g[j][i] == 'X')
++cnt, ++j;
if(cnt >= 5)
return true;
}
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j) {
if(g[i][j] == 'X') {
int cnt = 0;
for(int k = i, l = j; k < 10 && l < 10 && g[k][l] == 'X'; ++k, ++l, ++cnt);
if(cnt >= 5)
return true;
cnt = 0;
for(int k = i, l = j; k >= 0 && l >= 0 && g[k][l] == 'X'; ++k, --l, ++cnt);
if(cnt >= 5)
return true;
}
}
return false;
}
int main() {
for(int i = 0; i < 10; ++i)
scanf("%s", g[i]);
for(int i = 0; i < 10; ++i)
for(int j = 0; j < 10; ++j)
if(g[i][j] == '.') {
g[i][j] = 'X';
if(check()) {
puts("YES");
return 0;
}
g[i][j] = '.';
}
puts("NO");
return 0;
}