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