[C]38th ITSA Problem 2
第二題也還蠻簡單的 其實沒什麼需要注意的地方
#include <stdio.h> int ooxx[3][3]; void initarray(){ int i,j; for(i=0;i<3;i++) for(j=0;j<3;j++) ooxx[i][j]=0; } void printResult(char winner){ int i,j; //印出井字內容 for(i=0;i<3;i++){ for(j=0;j<3;j++) if(ooxx[i][j]==0) printf("*"); else printf("%c",ooxx[i][j]==1?'Y':'X'); printf("\n"); } //印出贏家 printf(winner=='T'?"Tie\n":"%c bingle\n",winner); } int main(int argc, char *argv[]) { int c=0,i; char winner[1]={'T'}; initarray(); while(scanf("%d %d %d",&ooxx[c][0],&ooxx[c][1],&ooxx[c][2])==3){ ++c; if(c==3){ //判斷行&列是否bingle & 贏家 for(i=0;i<3;i++){ if(ooxx[i][0]==ooxx[i][1]&&ooxx[i][0]==ooxx[i][2]){ winner[0]=ooxx[i][0]==1?'Y':'X'; }else if(ooxx[0][i]==ooxx[1][i]&&ooxx[0][i]==ooxx[2][i]){ winner[0]=ooxx[0][i]==1?'Y':'X'; } } //判斷兩對角線是否bingle & 贏家 if(ooxx[0][0]==ooxx[1][1]&&ooxx[0][0]==ooxx[2][2]||ooxx[0][2]==ooxx[1][1]&&ooxx[0][2]==ooxx[2][0]) winner[0]=ooxx[1][1]==1?'Y':'X'; //印出 & 初始化陣列&贏家 printResult(winner[0]); initarray(); c=0; winner[0]='T'; } return 0; }以上為個人淺解 還請各位大大多多指教
留言
張貼留言