题解 | #井字棋#
井字棋
https://www.nowcoder.com/practice/0375c1d206ef48a3894f72aa07b2fdde
#include <stdio.h> int main() { char arr[3][3]; int i = 0; int j = 0; for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { scanf("%c ",*(arr+i)+j); } } if(arr[0][0] == arr[1][1] && arr[1][1]== arr[2][2]) { if(arr[0][0] == 'K') { printf("KiKi wins!\n"); return 0; } else if(arr[0][0] == 'B') { printf("BoBo wins!\n"); return 0; } } if(arr[0][2] == arr[1][1] && arr[1][1] == arr[2][0]) { if(arr[1][1] == 'K') { printf("KiKi wins!\n"); return 0; } else if(arr[1][1] == 'B') { printf("BoBo wins!\n"); return 0; } } //行 for(i = 0; i < 3; i++) { if(arr[i][0] == arr[i][1] && arr[i][1] == arr[i][2]) { if(arr[i][0] == 'K') { printf("KiKi wins!\n"); return 0; } else if(arr[1][1] == 'B') { printf("BoBo wins!"); return 0; } } } //列 for(j = 0; j < 3; j++) { if(arr[0][j] == arr[1][j] && arr[1][j] == arr[2][j]) { if(arr[0][j] == 'K') { printf("KiKi wins!\n"); return 0; } else if(arr[0][j] == 'B') { printf("BoBo wins!"); return 0; } } } printf("No winner!\n"); return 0; }