-
Notifications
You must be signed in to change notification settings - Fork 0
/
TOE2 - Tic-Tac-Toe ( II ).cpp
93 lines (78 loc) · 2.26 KB
/
TOE2 - Tic-Tac-Toe ( II ).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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j,noX,noO,flag,winX,winO;
while(1)
{
string str;
cin>>str;
noX = noO = flag = winX = winO = 0;
if(str[0]=='e')
break;
for(i=0; i<9; i++)
{
if(str[i] == 'X')
noX++;
else if(str[i] == 'O')
noO++;
}
if(str[4] != '.')
{
if(str[4] == 'O')
{
if((str[0] == 'O' && str[8] == 'O') || (str[1] == 'O' && str[7] == 'O') || (str[2] == 'O' && str[6] == 'O') || (str[3] == 'O' && str[5] == 'O'))
winO = 1;
}
else
{
if((str[0] == 'X' && str[8] == 'X') || (str[1] == 'X' && str[7] == 'X') || (str[2] == 'X' && str[6] == 'X') || (str[3] == 'X' && str[5] == 'X'))
winX = 1;
}
}
if(str[1] != '.')
{
if(str[0] == 'O')
{
if((str[3] == 'O' && str[6] == 'O') || (str[1] == 'O' && str[2] == 'O'))
winO =1;
}
else
{
if((str[3] == 'X' && str[6] == 'X') || (str[1] == 'X' && str[2] == 'X'))
winX =1;
}
}
if(str[8] != '.')
{
if(str[8] == 'O')
{
if((str[5] == 'O' && str[2] == 'O') || (str[7] == 'O' && str[6] == 'O'))
winO = 1;
}
else
{
if((str[5] == 'X' && str[2] == 'X') || (str[7] == 'X' && str[6] == 'X'))
winX = 1;
}
}
if(winX == 1 && winO == 1)
flag = 1;
else
{
if(winX == 1 && winO == 0 && noX != noO + 1)
flag = 1;
else if(winX == 0 && winO == 1 && noX != noO)
flag = 1;
else if(winX == 0 && winO == 0 && (noX != 5 || noO != 4))
{
flag = 1;
}
}
if(flag)
printf("invalid\n");
else
printf("valid\n");
}
return 0;
}