Skip to content

Commit 0ca5712

Browse files
committed
Added 1846B - Rudolph and Tic-Tac-Toe.cpp
1 parent 5f4a635 commit 0ca5712

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

1846B - Rudolph and Tic-Tac-Toe.cpp

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// ॐ नमः शिवाय
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
#define ll long long
6+
#define pb push_back
7+
#define ff first
8+
#define ss second
9+
#define mp make_pair
10+
11+
// Code Written By: Vikash Patel
12+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
13+
14+
string solve(vector<vector<char>> m)
15+
{
16+
string d1, d2;
17+
int k = -1;
18+
for(int i=0; i<3; i++)
19+
{
20+
k++;
21+
string s1, s2;
22+
for(int j=0; j<3; j++)
23+
{
24+
s1 += m[i][j];
25+
s2 += m[j][k];
26+
if(i == j)
27+
d1 += m[i][j];
28+
}
29+
if(s1 == "XXX" || s2 == "XXX")
30+
return "X";
31+
else if(s1 == "OOO" || s2 == "OOO")
32+
return "O";
33+
else if(s1 == "+++" || s2 == "+++")
34+
return "+";
35+
}
36+
d2 += m[2][0];
37+
d2 += m[1][1];
38+
d2 += m[0][2];
39+
if(d1 == "XXX" || d2 == "XXX")
40+
return "X";
41+
else if(d1 == "OOO" || d2 == "OOO")
42+
return "O";
43+
else if(d1 == "+++" || d2 == "+++")
44+
return "+";
45+
46+
return "DRAW";
47+
}
48+
49+
int main()
50+
{
51+
ios_base::sync_with_stdio(0);
52+
cin.tie(0);
53+
cout.tie(0);
54+
55+
// #ifndef ONLINE_JUDGE
56+
// freopen("input.txt", "r", stdin);
57+
// freopen("/Users/vikash/Desktop/output.txt", "w", stdout);
58+
// #endif
59+
60+
int t;
61+
cin>>t;
62+
while(t--)
63+
{
64+
string a, b, c;
65+
cin>>a>>b>>c;
66+
vector<vector<char>> m = {{a[0], a[1], a[2]}, {b[0], b[1], b[2]}, {c[0], c[1], c[2]}};
67+
cout<<solve(m)<<endl;
68+
}
69+
return 0;
70+
}

0 commit comments

Comments
 (0)