10363

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
int xwin[8];
int owin[8];
/*
1
XX.
XX.
OOO
*/
string str[4];
bool rowcheck(char c)
{
	for(int i=0;i<3;i++)
	{
		if(str[i][0]==str[i][1] && str[i][0]==str[i][2] && str[i][0]==c)
			return 1;
	}
	return 0;
}
bool diagncheck(char c)
{
	if(str[0][0]==str[1][1] && str[1][1]==str[2][2] && str[1][1]==c)
		return 1;
	if(str[0][2]==str[1][1] && str[1][1]==str[2][0] && str[1][1]==c)
		return 1;
	return 0;
}
bool columncheck(char c)
{
	for(int i=0;i<3;i++)
	{
		if(str[0][i]==c && str[0][i]==str[1][i] && str[0][i]==str[2][i])
			return 1;
	}
	return 0;
}

int main()
{
	int n,x=0,o=0;
	string s;
	scanf("%d",&n);
	getchar();

	while(n--)
	{
		x = 0;
		o = 0;
		for(int cnt=0;cnt<3;cnt++)
		{
			getline(cin,s);
			str[cnt]=s;
			for(int i=0;i<3;i++)
			{
				if(str[cnt][i]=='O')
					o+=1;
				if(str[cnt][i]=='X')
					x+=1;
			}
		}
		if(!(x==o+1) && !(x==o))
		printf("no\n");
		else
		{
			bool r1,r2,c2,c1,d1,d2;
			r1 = rowcheck('O');
			r2 = rowcheck('X');

			c1 = columncheck('O');
			c2 = columncheck('X');

			d1 = diagncheck('O');
			d2 = diagncheck('X');
			//cout<<r2<<" "<<c2<<" "<<d2<<"\n";
			//cout<<(r2||c2||d2)<<"\n";
			if((r2||c2||d2) == 1 && (r1||c1||d1) == 1)
				printf("no\n");
			else if( (r2||c2||d2) == 1 && !(x==o+1))
				printf("no\n");
			else if( (r1||c1||d1) == 1 && (x!=o))
				printf("no\n");
			else
				printf("yes\n");
		}
		if(n)
		getline(cin,s);
	}
	return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *