-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10363.cpp
73 lines (64 loc) · 1.7 KB
/
P10363.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
#include <iostream>
#include <cstdio>
using namespace std;
int count(string &s1, string &s2, string &s3, char color) {
int ret = 0;
for(int i = 0; i < 3; ++i) {
if(s1[i] == color) ++ret;
if(s2[i] == color) ++ret;
if(s3[i] == color) ++ret;
}
cerr << "Count " << color << ": " << ret << endl;
return ret;
}
bool wins(string &s1, string &s2, string &s3, char color) {
if(s1[0] == color && s2[1] == color && s3[2] == color)
return true;
if(s3[0] == color && s2[1] == color && s1[2] == color)
return true;
if(s1[0] == color && s1[1] == color && s1[2] == color)
return true;
if(s2[0] == color && s2[1] == color && s2[2] == color)
return true;
if(s3[0] == color && s3[1] == color && s3[2] == color)
return true;
for(int i = 0; i < 3; ++i) {
if(s1[i] == color && s2[i] == color && s3[i] == color)
return true;
}
return false;
}
bool ok(bool winX, bool winO, int countX, int countO) {
if(winX) {
if(winO)
return false;
return countX-1 == countO;
}
else if(winO) {
return countX == countO;
}
else {
// No win: Check counts:
return countX == countO || countX-1 == countO;
}
}
int main() {
int cases;
string s1, s2, s3;
cin >> cases;
for(int cas = 0; cas < cases; ++cas) {
cin >> s1 >> s2 >> s3;
cerr << s1 << endl << s2 << endl << s3 << endl;
int countX = count(s1, s2, s3, 'X');
int countO = count(s1, s2, s3, 'O');
bool winX = wins(s1, s2, s3, 'X');
bool winO = wins(s1, s2, s3, 'O');
cerr << "Wins X: " << winX << ", Win O: " << winO << endl;
bool isOK = ok(winX, winO, countX, countO);
if(isOK)
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}