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