-
Notifications
You must be signed in to change notification settings - Fork 0
/
ticTacToe.cpp
80 lines (70 loc) · 1.94 KB
/
ticTacToe.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
// codeforces, Rudolph and Tic-Tac-Toe
#include <bits/stdc++.h>
using namespace std;
// #define ll unsigned long long int;
bool checkHorizontal(char result[3][3], char sym)
{
if (result[0][0] == sym && result[0][1] == sym && result[0][2] == sym)
return true;
if (result[1][0] == sym && result[1][1] == sym && result[1][2] == sym)
return true;
if (result[2][0] == sym && result[2][1] == sym && result[2][2] == sym)
return true;
return false;
};
bool checkVertical(char result[3][3], char sym)
{
if (result[0][0] == sym && result[1][0] == sym && result[2][0] == sym)
return true;
if (result[0][1] == sym && result[1][1] == sym && result[2][1] == sym)
return true;
if (result[0][2] == sym && result[1][2] == sym && result[2][2] == sym)
return true;
return false;
};
bool checkDiagonal(char result[3][3], char sym)
{
if (result[0][0] == sym && result[1][1] == sym && result[2][2] == sym)
return true;
if (result[2][0] == sym && result[1][1] == sym && result[0][2] == sym)
return true;
return false;
};
void solve()
{
char result[3][3];
int countD = 0;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cin >> result[i][j];
}
}
if(checkHorizontal(result,'X')||checkVertical(result,'X')||checkDiagonal(result,'X')){
cout<<"X"<<endl;
return;
}
if(checkHorizontal(result,'O')||checkVertical(result,'O')||checkDiagonal(result,'O')){
cout<<"O"<<endl;
return;
}
if(checkHorizontal(result,'+')||checkVertical(result,'+')||checkDiagonal(result,'+')){
cout<<"+"<<endl;
return;
}
cout<<"DRAW"<<endl;
return;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int testCases;
cin >> testCases;
while (testCases--)
solve();
return 0;
}