满江红,样例过
  • 板块CF3C Tic-tac-toe
  • 楼主zzr1208
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/10/23 22:03
  • 上次更新2023/10/23 22:28:24
查看原帖
满江红,样例过
754569
zzr1208楼主2023/10/23 22:03
#include <bits/stdc++.h>
using namespace std;
char p[3][3];
int a=0,b=0,c=0;
void check_win()
{
	//player a
	if(p[0][0]=='X'&&p[0][1]=='X'&&p[0][2]=='X'){printf("the first player won");exit(0);}
	if(p[1][0]=='X'&&p[1][1]=='X'&&p[1][2]=='X'){printf("the first player won");exit(0);}
	if(p[2][0]=='X'&&p[2][1]=='X'&&p[2][2]=='X'){printf("the first player won");exit(0);}
	/*----------------横向-------------------*/
	if(p[0][0]=='X'&&p[1][0]=='X'&&p[2][0]=='X'){printf("the first player won");exit(0);}
	if(p[0][1]=='X'&&p[1][1]=='X'&&p[2][1]=='X'){printf("the first player won");exit(0);}
	if(p[0][2]=='X'&&p[1][2]=='X'&&p[2][2]=='X'){printf("the first player won");exit(0);}
	/*----------------竖向-------------------*/
	if(p[0][0]=='X'&&p[1][1]=='X'&&p[2][2]=='X'){printf("the first player won");exit(0);}
	if(p[0][2]=='X'&&p[1][1]=='X'&&p[2][0]=='X'){printf("the first player won");exit(0);}
	/*----------------斜向-------------------*/
	//player b
	if(p[0][0]=='0'&&p[0][1]=='0'&&p[0][2]=='0'){printf("the second player won");exit(0);}
	if(p[1][0]=='0'&&p[1][1]=='0'&&p[1][2]=='0'){printf("the second player won");exit(0);}
	if(p[2][0]=='0'&&p[2][1]=='0'&&p[2][2]=='0'){printf("the second player won");exit(0);}
	/*----------------横向-------------------*/
	if(p[0][0]=='0'&&p[1][0]=='0'&&p[2][0]=='0'){printf("the second player won");exit(0);}
	if(p[0][1]=='0'&&p[1][1]=='0'&&p[2][1]=='0'){printf("the second player won");exit(0);}
	if(p[0][2]=='0'&&p[1][2]=='0'&&p[2][2]=='0'){printf("the second player won");exit(0);}
	/*----------------竖向-------------------*/
	if(p[0][0]=='0'&&p[1][1]=='0'&&p[2][2]=='0'){printf("the second player won");exit(0);}
	if(p[0][2]=='0'&&p[1][1]=='0'&&p[2][0]=='0'){printf("the second player won");exit(0);}
	/*----------------斜向-------------------*/
}
void check_go()
{
	if(a>b){printf("second");exit(0);}
	if(a==b){printf("first");exit(0);}
}
void check_no()
{
	if(abs(a-b)>1||b>a){printf("illegal");exit(0);}
}
int main()
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
		{
			cin>>p[i][j];
			if(p[i][j]=='X') a++;
			if(p[i][j]=='0') b++;
			if(p[i][j]=='.') c++;
		}
	check_win();
	check_go();
	check_no();
	printf("draw");
	//printf("X=%d 0=%d .=%d",a,b,c);
	return 0;
}
2023/10/23 22:03
加载中...