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