-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path1161_TOE1.cpp
136 lines (127 loc) · 2.13 KB
/
1161_TOE1.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
TASK: Tic-Tac-Toe ( I )
Input:
6
X.O
OO.
XXX
O.X
XX.
OOO
XXO
OOX
OXX
XXX
OO.
..O
XXX
OOO
...
0X0
XXX
0X0
Output:
yes
no
no
no
no
no
*/
#include <iostream>
#include <vector>
using namespace std;
int num(string m, char c)
{
int ret=0;
for(int i=0;i<m.length();i++)
if(m[i]==c)
ret++;
return ret;
}
bool success(string m, char c)
{
for(int i=0;i<3;i++)
if((m[i*3]==c)&&(m[i*3+1]==c)&&(m[i*3+2]==c))
return true;
for(int i=0;i<3;i++)
if((m[i]==c)&&(m[i+3]==c)&&(m[i+6]==c))
return true;
if((m[0]==c)&&(m[4]==c)&&(m[8]==c))
return true;
if((m[2]==c)&&(m[4]==c)&&(m[6]==c))
return true;
return false;
}
bool isOK(string m)
{
int nO=num(m, 'O');
int nX=num(m, 'X');
//printf("nO = %d, nX = %d\n", nO, nX);
if(nO>nX)
return false;
else if(nO==nX)
{
//Should No success X
if(success(m, 'X'))
return false;
}
else
{
if(success(m, 'O'))
return false;
if(nX>nO+1)
return false;
}
return true;
}
int main()
{
/*//case 1
if(isOK("X.OOO.XXX"))
printf("correct!\n");
else
printf("wrong!\n");
//case 2
if(isOK("O.XXX.OOO"))
printf("wrong!\n");
else
printf("correct!\n");
//case 3
if(isOK("XXOOOXOXX"))
printf("wrong!\n");
else
printf("correct!\n");
//case 4
if(isOK("XXXOO...O"))
printf("wrong!\n");
else
printf("correct!\n");
//case 5
if(isOK("XXXOOO..."))
printf("wrong!\n");
else
printf("correct!\n");*/
int i, tN;
scanf("%d", &tN);
vector<string> inputs(tN);
for(i=0;i<tN;i++)
{
char line[3];
scanf("%s", line);
inputs[i]=line;
scanf("%s", line);
inputs[i]+=line;
scanf("%s", line);
inputs[i]+=line;
}
for(i=0;i<tN;i++)
{
//printf("%s\n", inputs[i].c_str());
if(isOK(inputs[i]))
printf("yes\n");
else
printf("no\n");
}
return 0;
}