Codeforces Round #390 (Div. 2), problem: (B) Ilya and tic-tac-toe game Solution in C/C++

Codeforces Round #390 (Div. 2), problem: (B) Ilya and tic-tac-toe game Solution in C/C++

#include<stdio.h>
#include<stdlib.h>
typedef unsigned u;
char S[4][4];u x,o;
void chk(u r,u c,u dr,u dc,u s,u l)
{
	if(!(dr|dc))dr=-(dc=1);
	if(r>3||c>3){x=o=0;return;}
	if(l)x=o=0;
	if(S[r][c]=='x')++x;
	if(S[r][c]=='o')++o;
	if(s)chk(r+dr,c+dc,dr,dc,s-1,0);
	return;
}
int main()
{
	u i,j,k;
	scanf("%s%s%s%s",S[0],S[1],S[2],S[3]);
	for(i=-1;++i<4;)for(j=-1;++j<4;)for(k=-1;++k<4;)
	{
		chk(i,j,k>>1,k&1,2,1);
		if(x==2&&o==0){printf("YES\n");return 0;}
	}
	printf("NO\n");
	return 0;
}

Codeforces Round #390 (Div. 2), problem: (B) Ilya and tic-tac-toe game Solution in C/C++

#include<stdio.h>
#include<stdlib.h>
typedef unsigned u;
char S[4][4];u x,o;
void chk(u r,u c,u dr,u dc,u s,u l)
{
	if(!(dr|dc))dr=-(dc=1);
	if(r>3||c>3){x=o=0;return;}
	if(l)x=o=0;
	if(S[r][c]=='x')++x;
	if(S[r][c]=='o')++o;
	if(s)chk(r+dr,c+dc,dr,dc,s-1,0);
	return;
}
int main()
{
	u i,j,k;
	scanf("%s%s%s%s",S[0],S[1],S[2],S[3]);
	for(i=-1;++i<4;)for(j=-1;++j<4;)for(k=-1;++k<4;)
	{
		chk(i,j,k>>1,k&1,2,1);
		if(x==2&&o==0){printf("YES\n");return 0;}
	}
	printf("NO\n");
	return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

7 Reasons This Viral Kitchen Gadgets Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.If you had told me six months ago that a single purchase would change how...

Company of Heroes 3 Final Stand Update v2.5.6.50313-RUNE

Company of Heroes 3 Receives Final Stand Update v2.5.6 Strategy enthusiasts and World War II tactics fans have a new reason to dive back into...

Everything You Need to Know About Viral Kitchen Gadgets Right Now

📢 As an Amazon Associate, I earn from qualifying purchases.If you had told me six months ago that a single purchase would change how...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!