NEU 1515 Play with bear kid

本文介绍了一个简单的模拟题,通过判断3*3棋盘上熊孩子与玩家的棋子布局来确定胜负。该文提供了C++实现代码,演示了如何检查水平、垂直及对角线上的棋子是否构成胜利条件。

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

提示

 

来源

2015.2

 

东北大学二月月赛第一题

简单的模拟题,分别判断同一行,同一列,对角线和反对角线四种情况就可以了。

 

 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++]

 

 

转载于:https://www.cnblogs.com/lzj-0218/p/4304547.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值