#include <stdio.h> int main(){ char a[3][3]; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { scanf("%c",&a[i][j]); getchar(); } // scanf("\n"); } for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { printf("%c ",a[i][j]); } printf("\n"); } int countX = 0,countO = 0; for (int i = 0; i < 3; ++i) { countO = countX = 0; for (int j = 0; j < 3; ++j) { if(a[i][j] == '*'){ countX++; }else if(a[i][j] == 'O'){ countO++; } } // printf("%d %d\n",countX,countO); // printf("first\n"); if(countO == 3){ printf("O win\n"); return 0; }else if (countX == 3){ printf("X win\n"); return 0; } } for (int i = 0; i < 3; ++i) { countO = countX = 0; for (int j = 0; j < 3; ++j) { if(a[j][i] == '*'){ countX++; }else if(a[j][i] == 'O'){ countO++; } } // printf("second\n"); // printf("%d %d\n",countX,countO); if(countO == 3){ printf("O win\n"); return 0; }else if (countX == 3){ printf("X win\n"); return 0; } } for (int i = 0,countO = countX = 0; i < 3; ++i) { if(a[i][i] == '*'){ countX++; }else if(a[i][i] == 'O'){ countO++; } // printf("third\n"); // printf("%d %d\n",countX,countO); if(countO == 3){ printf("O win\n"); return 0; }else if (countX == 3){ printf("X win\n"); return 0; } } for (int i = 0,countO = countX = 0; i < 3; ++i) { if(a[i][2-i] == '*'){ countX++; }else if(a[i][2-i] == 'O'){ countO++; } // printf("fourth\n"); // printf("%d %d\n",countX,countO); if(countO == 3){ printf("O win\n"); return 0; }else if (countX == 3){ printf("X win\n"); return 0; } } return 0; }
标签:判断,return,countO,++,井字棋,countX,int,printf,输赢 From: https://www.cnblogs.com/xinrenbool/p/16950711.html