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