#include <stdio.h> char isWin(char board[3][3]) { int i, j, flag = 1; //判断行 for (i = 0; i < 3; i++) { flag = 1; for (j = 0; j < 2; j++) { if (board[i][j] == board[i][j + 1] && board[i][j] != 'O') { ; } else { flag = 0; break; } } if (flag) return board[i][j]; } //判断列 for (i = 0; i < 3; i++) { flag = 1; for (j = 0; j < 2; j++) { if (board[j][i] == board[j + 1][i] && board[j][i] != 'O') { ; } else { flag = 0; break; } } if (flag) return board[j][i]; } //判断对角线 //判断主对角线 flag = 1; for (i = 0; i < 2; i++) { if (board[i][i] == board[i + 1][i + 1] && board[i][i] != 'O') { ; } else { flag = 0; break; } } if (flag) return board[i][i]; //判断副对角线 flag = 1; for (j = 0; j < 2; j++) { if (board[j][2 - j] == board[j + 1][1 - j] && board[j][2 - j] != 'O') { ; } else { flag = 0; break; } } if (flag) return board[j][2 - j]; //棋盘满了,没有人获胜 return 'O'; } int main() { char board[3][3] = {0}; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { scanf("%c ", &board[i][j]); } } if (isWin(board) == 'K') printf("KiKi wins!"); else if (isWin(board) == 'B') printf("BoBo wins!"); else printf("No winner!"); return 0; }