哪里错了……
  • 板块CF3C Tic-tac-toe
  • 楼主dp_hater
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/12/2 21:31
  • 上次更新2023/10/27 00:41:49
查看原帖
哪里错了……
657210
dp_hater楼主2022/12/2 21:31
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long sln;
char a[5][5];
int win(){
	int ret=0;
	if(a[0][0]==a[1][1]&&a[1][1]==a[2][2]&&a[0][0]!='.'||a[0][0]==a[1][0]&&a[1][0]==a[2][0]&&a[0][0]!='.'||a[0][0]==a[0][1]&&a[0][1]==a[0][2]&&a[0][0]!='.'){
		if(a[0][0]=='0'){

			if(!ret)ret=2;

			if(!ret)ret=1;
			else ret=3;
		}
	}
	if(a[0][1]==a[1][1]&&a[1][1]==a[2][1]&&a[1][1]!='.'||a[1][0]==a[1][1]&&a[1][1]==a[0][2]&&a[1][1]!='.'){
		if(a[1][1]=='0'){
			if(!ret)ret=2;
			else ret=3;
		} 
		else{
			if(!ret)ret=1;
			else ret=3;
		}
	}
	if(a[2][2]==a[1][2]&&a[1][2]==a[0][2]&&a[0][2]!='.'||a[2][2]==a[2][1]&&a[2][1]==a[2][0]&&a[2][2]!='.'){
		if(a[2][2]=='0'){
			if(!ret)ret=2;
			else ret=3;
		} 
		else{
			if(!ret)ret=1;
			else ret=3;
		}
	}
	if(a[2][0]==a[1][1]&&a[1][1]==a[0][2]&&a[0][2]!='.'){
		if(a[2][2]=='0'){
			if(!ret)ret=2;
			else ret=3;
		} 
		else{
			if(!ret)ret=1;
			else ret=3;
		}
	}
	return ret;
}
void panduan(){
	int x=0,y=0;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(a[i][j]=='0') x++;
			else if(a[i][j]=='X') y++;
		}
	}
	int ifwin=win();
	if(x>y||x+2<=y||ifwin==3||ifwin==2&&x!=y||ifwin==1&&x==y) cout<<"illegal";
	else if(ifwin==0){
		if(y+x==9) cout<<"draw";
		else if(y>x) cout<<"second";
		else cout<<"first";
	}
	else{
		if(ifwin==1) cout<<"the first player won";
		else cout<<"the second player won";
	}
}
signed main(){
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	panduan();
	return 0;
}

测试点十一红了
2022/12/2 21:31
加载中...