Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<string>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--){
- char g[5][5];
- cin>>g[1][1]>>g[1][2]>>g[1][3];
- cin>>g[2][1]>>g[2][2]>>g[2][3];
- cin>>g[3][1]>>g[3][2]>>g[3][3];
- int i,j,xcnt=0,ocnt=0,n;
- for(i=1;i<=3;i++){
- for(j=1;j<=3;j++){
- if(g[i][j]=='X')
- xcnt++;
- if(g[i][j]=='O')
- ocnt++;
- }
- }
- if(ocnt>xcnt){
- cout<<"no"<<endl;
- continue;
- }
- n=xcnt-ocnt;
- if(n>1){
- cout<<"no"<<endl;
- continue;
- }
- if(n==0){
- if(g[1][1]=='X'){
- if(g[1][2]=='X' && g[1][3]=='X'){
- cout<<"no"<<endl;
- continue;
- }
- if(g[2][1]=='X' && g[3][1]=='X'){
- cout<<"no"<<endl;
- continue;
- }
- if(g[2][2]=='X' && g[3][3]=='X'){
- cout<<"no"<<endl;
- continue;
- }
- }
- if(g[1][3]=='X'){
- if(g[2][3]=='X' && g[3][3]=='X'){
- cout<<"no"<<endl;
- continue;
- }
- if(g[2][2]=='X' && g[3][1]=='X'){
- cout<<"no"<<endl;
- continue;
- }
- }
- if(g[1][2]=='X'){
- if(g[2][2]=='X' && g[3][2]=='X'){
- cout<<"no"<<endl;
- continue;
- }
- }
- if(g[2][1]=='X'){
- if(g[2][2]=='X' && g[2][3]=='X'){
- cout<<"no"<<endl;
- continue;
- }
- }
- if(g[3][1]=='X'){
- if(g[3][2]=='X' && g[3][3]=='X'){
- cout<<"no"<<endl;
- continue;
- }
- }
- }
- if(n==1){
- if(g[1][1]=='O'){
- if(g[1][2]=='O' && g[1][3]=='O'){
- cout<<"no"<<endl;
- continue;
- }
- if(g[2][1]=='O' && g[3][1]=='O'){
- cout<<"no"<<endl;
- continue;
- }
- if(g[2][2]=='O' && g[3][3]=='O'){
- cout<<"no"<<endl;
- continue;
- }
- }
- if(g[1][3]=='O'){
- if(g[2][3]=='O' && g[3][3]=='O'){
- cout<<"no"<<endl;
- continue;
- }
- if(g[2][2]=='O' && g[3][1]=='O'){
- cout<<"no"<<endl;
- continue;
- }
- }
- if(g[1][2]=='O'){
- if(g[2][2]=='O' && g[3][2]=='O'){
- cout<<"no"<<endl;
- continue;
- }
- }
- if(g[2][1]=='O'){
- if(g[2][2]=='O' && g[2][3]=='O'){
- cout<<"no"<<endl;
- continue;
- }
- }
- if(g[3][1]=='O'){
- if(g[3][2]=='O' && g[3][3]=='O'){
- cout<<"no"<<endl;
- continue;
- }
- }
- }
- cout<<"yes"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement