|
|
back to boardWhy WA#1?Where is mistake?Thank!!! Posted by Search 16 Mar 2008 15:05 #include<iostream.h> int main() { char a[4][4];int i,j;bool p=true,k=true; for(i=1;i<=3;i++) for(j=1;j<=3;j++) cin>>a[i][j]; if(a[2][2]=='#'&&(a[1][1]=='X'&&a[1][3]=='X')||(a[3][1]=='X'&&a[3][3]=='X')) cout<<"Crosses win"<<endl; else{ for(i=1;i<=3;i++) for(j=1;j<=3;j++) if(a[i][j]=='#'&&p) {if(a[i-1][j-1]=='X'&&a[i+1][j+1]=='X') {cout<<"Crosses win"<<endl;p=false;} else if(a[i-1][j+1]=='X'&&a[i+1][j-1]=='X') {cout<<"Crosses win"<<endl;p=false;} else if(a[i][j-1]=='X'&&a[i][j+1]=='X') {cout<<"Crosses win"<<endl;p=false;} else if(a[i-1][j]=='X'&&a[i+1][j]=='X') {cout<<"Crosses win"<<endl;p=false;} else if(a[i-1][j-1]=='O'&&a[i+1][j+1]=='O') {cout<<"Ouths win"<<endl;p=false;} else if(a[i-1][j+1]=='O'&&a[i+1][j-1]=='O') {cout<<"Ouths win"<<endl;p=false;} else if(a[i][j-1]=='O'&&a[i][j+1]=='O') {cout<<"Ouths win"<<endl;p=false;} else if(a[i-1][j]=='O'&&a[i+1][j]=='O') {cout<<"Ouths win"<<endl;p=false;}
} for(i=1;i<=3;i++) for(j=1;j<=3;j++) {if(a[i][j]!='#'&&k&&p) {if(a[i][j]=='X'&&k&&p) if((a[i-1][j-1]=='X') ||(a[i+1][j+1]=='X')||(a[i+1][j-1]=='X')||(a[i-1][j+1]=='X')||(a[i-1][j]=='X')||(a[i+1][j]=='X')||(a[i][j-1]=='X')||(a[i][j+1]=='X')) {cout<<"Crosses win"<<endl;k=false;p=true;} } else if(a[i][j]=='O'&&k&&p) if((a[i-1][j-1]=='O') ||(a[i+1][j+1]=='O')||(a[i+1][j-1]=='O')||(a[i-1][j+1]=='O')||(a[i-1][j]=='O')||(a[i+1][j]=='O')||(a[i][j-1]=='O')||(a[i][j+1]=='O')) {cout<<"Ouths win"<<endl;k=false;p=true;} }
if(p==true&&k==true) cout<<"Draw"<<endl; } return 0; } On my computer for 1-st test from problem's statement answer is right. Where mistake?Thank!!! |
|
|