Help!I have problem with 3C!
Difference between en1 and en2, changed 1,812 character(s)
I have problem with problem 3C.↵
This is my submisson:[submission:139851350]↵
Source code:#include<iostream>↵
using namespace std;↵
class chess{↵
public:↵
int cnt0,cntx;↵
int chs[3][3];↵
};↵
give(chess c){↵
string str[3];↵
cin>>str[0]>>str[1]>>str[2];↵
for(int i=0;i<3;i++){↵
for(int j=0;j<3;j++){↵
if(str[i][j]=='.'){↵
c.chs[i][j]=0;↵
}↵
if(str[i][j]=='0'){↵
c.chs[i][j]=1;↵
c.cnt0++;↵
}↵
if(str[i][j]=='X'){↵
c.chs[i][j]=2;↵
c.cntx++;↵
}↵
}↵
}↵
}↵
bool win(chess c,int num){↵
bool acr=false;↵
for(int i=0;i<3;i++){↵
bool acr_=true;↵
for(int j=0;j<3;j++){↵
acr_=acr_&&(c.chs[i][j]==num);↵
}↵
acr=acr||acr_;↵
}↵
bool dow=false;↵
for(int i=0;i<3;i++){↵
bool dow_=true;↵
for(int j=0;j<3;j++){↵
dow_=dow_&&(c.chs[j][i]==num);↵
}↵
dow=dow||dow_;↵
}↵
bool bl=false;//0 0 0↵
bool bl0=true;//0 0 0↵
bool bl1=true;//0 0 0↵
for(int i=0;i<3;i++){↵
bl0=bl0&&c.chs[i][i]==num;↵
bl1=bl1&&c.chs[i][2-i]==num; ↵
}↵
bl=bl||bl0;↵
bl=bl||bl1;↵
bool result=bl||dow;↵
result=bl||acr;↵
return result;↵
}↵
bool isillegal(chess c){↵
int X0=c.cntx-c.cnt0;↵
if(X0<0||X0>1){↵
return false;↵
}↵
if(win(c,1)&&win(c,2)){↵
return false;↵
}↵
if(win(c,1)&&c.cntx>c.cnt0){↵
return false;↵
}↵
if(win(c,2)&&c.cntx==c.cnt0){↵
return false;↵
}↵
return true;↵
}↵
bool isdraw(chess c){↵
int cntused=c.cnt0+c.cntx;↵
if(cntused==9&&!win(c,1)&&!win(c,2)){↵
return true;↵
}↵
return false;↵
}↵
void solve(){↵
chess c;↵
give(c);↵
bool win0=win(c,1);↵
bool winx=win(c,2);↵
bool illc=isillegal(c);↵
bool draw=isdraw(c);↵
bool nextx=c.cnt0==c.cntx;↵
if(illc){cout<<"illegal";return;}↵
if(win0){cout<<"the second player won";return;}↵
if(winx){cout<<"the first player won";return;}↵
if(draw){cout<<"draw";return;}↵
if(nextx){cout<<"first";return;}↵
cout<<"second";↵
}↵
int main(){↵
solve(); ↵
return 0;↵
}↵

And its exit code is 2147483647!↵
I tried many times.↵
Please help me!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Eric12 2021-12-19 07:00:26 1812
en1 English Eric12 2021-12-19 06:55:32 1990 Initial revision (published)