Last Submissions | ||||||
---|---|---|---|---|---|---|
Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
| discuss10363 - | Accepted | C++11 | 0.000 | 0.000 | 1152 | 1 mins ago |
Problem:
- To read problem click on 10363
Suggest:
1. At first count O and count X if count O>count X || count X > count O + 1 then print "no" and continue.
2. Check is X win and is O win
----if both X and O win then print "no"
----if X win and count X is not greater than count O then print "no"
----if O win and count O is not equal count X then print "no"
----otherwise print "yes"
#include<bits/stdc++.h>
using namespace std;
char a[1001][1001];
bool x_win(){
// _
for(int i=1; i<=3; i++){
bool x_win= true;
for(int j=1; j<=3; j++)
if (a[i][j] != 'X') x_win=false;
if (x_win) return true;
}
// |
for(int i=1; i<=3; i++){
bool x_win= true;
for(int j=1; j<=3; j++)
if (a[j][i] != 'X') x_win=false;
if (x_win) return true;
}
// /
bool x_win= true;
for(int i=1; i<=3; i++){
if (a[i][i] != 'X') x_win=false;
}
if (x_win) return true;
// \ .
return (a[1][3] == a[2][2] && a[3][1] == a[2][2] && a[2][2] == 'X');
}
bool o_win(){
// _
for(int i=1; i<=3; i++){
bool o_win= true;
for(int j=1; j<=3; j++)
if (a[i][j] != 'O') o_win=false;
if (o_win) return true;
}
// |
for(int i=1; i<=3; i++){
bool o_win= true;
for(int j=1; j<=3; j++)
if (a[j][i] != 'O') o_win=false;
if (o_win) return true;
}
// /
bool o_win= true;
for(int i=1; i<=3; i++){
if (a[i][i] != 'O') o_win=false;
}
if (o_win) return true;
// \ .
return (a[1][3] == a[2][2] && a[3][1] == a[2][2] && a[2][2] == 'O');
}
string f(){
int o_cnt=0, x_cnt= 0;
for(int i=1; i<=3; i++)
for(int j=1; j<=3; j++)
if (a[i][j]=='X') x_cnt++;
else
if (a[i][j]=='O') o_cnt++;
if (o_cnt > x_cnt) return "no";
if (x_cnt > o_cnt + 1) return "no";
if (o_win() && x_win()) return "no";
if (x_win() && x_cnt <= o_cnt) return "no";
if (o_win() && x_cnt != o_cnt) return "no";
return "yes";
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int t; cin >> t;
while(t--){
for(int i=1; i<=3; i++)
for(int j=1; j<=3; j++)
cin >> a[i][j];
cout<<f()<<"\n";
}
}
No comments:
Post a Comment