1515: Play whit bear kid
时间限制: 1 Sec 内存限制: 128 MB提交: 3 解决: 2
题目描述
Happy Spring Festival everyone! Many relatives will visit your house, of course they have bear kids. Now you are playing chess with a bear kid.
It's really terrible. You have a 3*3 chessboard, bear kid puts 0s and you put 1s while the empty positions are '.' . The rule is that one whose
chess pieces are in a line horizontally, vertically or diagonally will win.
输入
There are several cases.
For each case, there is a 3*3 chessboard and the chess pieces have been put.
输出
You should judge whether someonw has won or not.
If the bear kid win, output "BEAR KID".
If you win, output "YOU".
Output "NO BODY" in other cases.
We guarantee you and bear kid won't win at the same time, and the number of 0s and 1s may be not the same.
样例输入
000
...
...
样例输出
BEAR KID
提示
来源
东北大学二月月赛第一题
简单的模拟题,分别判断同一行,同一列,对角线和反对角线四种情况就可以了。
1 #include<iostream> 2 #include<cstdio> 3 4 using namespace std; 5 6 char board[4][4]; 7 8 int main() 9 { 10 while(cin>>board[1][1]) 11 { 12 int result = 0; //result=0:NO BODY; result=1:YOU; result=2:BEAR KID 13 for(int i = 1; i <= 3; i++) 14 for(int j = 1; j <= 3; j++) 15 { 16 if(i == 1 && j == 1) 17 continue; 18 cin>>board[i][j]; 19 } 20 for(int i = 1; result == 0 && i <= 3; i++) 21 { 22 if(board[i][1] == board[i][2] && board[i][2] == board[i][3]) 23 { 24 if(board[i][1] == '1') 25 result = 1; 26 else if(board[i][1] == '0') 27 result = 2; 28 } 29 } 30 for(int j = 1; result == 0 && j <= 3; j++) 31 { 32 if(board[1][j] == board[2][j] && board[2][j] == board[3][j]) 33 { 34 if(board[1][j] == '1') 35 result = 1; 36 else if(board[1][j] == '0') 37 result = 2; 38 } 39 } 40 if(board[1][1] == board[2][2] && board[2][2] == board[3][3]) 41 if(board[1][1] == '1') 42 result = 1; 43 else if(board[1][1] == '0') 44 result = 2; 45 if(board[1][3] == board[2][2] && board[2][2] == board[3][1]) 46 if(board[1][3] == '1') 47 result = 1; 48 else if(board[1][3] == '0') 49 result = 2; 50 if(result == 0) 51 cout<<"NO BODY"<<endl; 52 else if(result == 1) 53 cout<<"YOU"<<endl; 54 else if(result == 2) 55 cout<<"BEAR KID"<<endl; 56 } 57 }