NEU 1515 Play with bear kid

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.php

輸入

There are several cases.
For each case, there is a 3*3 chessboard and the chess pieces have been put.ios

輸出

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.app

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.ide

樣例輸入

000
...
...

樣例輸出

BEAR KID

提示

 

來源

2015.2spa

 

東北大學二月月賽第一題code

簡單的模擬題,分別判斷同一行,同一列,對角線和反對角線四種狀況就能夠了。blog

 

 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 }
[C++]
相關文章
相關標籤/搜索