1515: Play whit bear kid 模拟题——(逻辑关系要注意)
来源:互联网 发布:青岛淘宝网店代运营 编辑:程序博客网 时间:2024/05/16 11:39
题目描述
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
题目的意思大致为给你已经摆好的一幅3*3棋盘,判断是谁赢。
直接判断横着的,竖着的和斜着的,这里注意,斜着的线有两条,不要漏掉。
#include<stdio.h>#include<string.h>int main(){char a[5][5];int i,j,k1=0,k2=0,k3=0,num1=0,num2=0;while(scanf("%s%s%s",a[0],a[1],a[2])!=EOF){k1=k2=k3=0;num1=num2=0;if((a[0][0]==a[1][1] && a[1][1]==a[2][2])||(a[0][2]==a[1][1] && a[1][1]==a[2][0])){if(a[1][1]=='0') {puts("BEAR KID"); k1++;}else if(a[1][1]=='1') {puts("YOU"); k1++;}}if(k1==0){for(i=0;i<3;i++){num1=num2=0;for(j=0;j<3;j++){if(a[i][j]=='0') num1++;else if(a[i][j]=='1') num2++;}if(num1==3) {puts("BEAR KID"); k2++; break;}else if(num2==3) {puts("YOU"); k2++; break;}}}if(k1==0 && k2==0){for(j=0;j<3;j++){num1=num2=0;for(i=0;i<3;i++){if(a[i][j]=='0') num1++;else if(a[i][j]=='1') num2++;}if(num1==3) {puts("BEAR KID"); k3++; break;}else if(num2==3) {puts("YOU"); k3++; break;}}}if(k1==0 && k2==0 && k3==0){puts("NO BODY");}//printf("%d%d%d\n",k1,k2,k3);}}
我一开始老是错掉,也不知道为什么,后来才发现是逻辑错误,一开始写if的地方都写成了else if,那么肯定错,因为执行了其中的一个else if后下面的就不会再进行了,所以这里就全改成if,然后就直接AC,不过也算是给我长了经验,哈哈。
- 1515: Play whit bear kid 模拟题——(逻辑关系要注意)
- HDU——1982Kaitou Kid - The Phantom Thief (1)(坑爹string题)
- 模拟赛#1补题 CodeForces 574A Bear and Elections(模拟+)
- 模拟赛#1补题 CodeForces 574B Bear and Three Musketeers(模拟判环)
- Python学习笔记(3)——逻辑关系
- Codeforces--658C--Bear and Forgotten Tree 3(模拟&&技巧)(好题)
- hdu 1982——Kaitou Kid - The Phantom Thief (1)
- CodeForces - 658A Bear and Reverse Radewoosh (模拟)水
- Codeforces--658A--Bear and Reverse Radewoosh(模拟)
- CodeForces - 628C Bear and String Distance (模拟)
- CodeForces - 673A Bear and Game (模拟)水
- CodeForces 658A Bear and Reverse Radewoosh(模拟)
- Let's go to play (模拟)
- [Play] route配置注意
- pytorch 模拟关系拟合——回归
- Java 框架 Play ——"Hello Play"
- Visual Basic 2008 运算符(算术、关系、逻辑、字符串连接、赋值、移位)——汇总
- 程序设计基础—什么是逻辑与、或、非关系?
- java web 学习
- dumpsys
- ViewController 的loadView、viewDidLoad、viewDidUnload分别是什么时候调用
- 详解 db file sequential read 等待事件
- 窗体继承
- 1515: Play whit bear kid 模拟题——(逻辑关系要注意)
- 刚才一段时间,csdn好像正常了。
- HDU -- 3665 Seaside (Floyd)
- Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'Info
- BOM与DOM
- 文章标题
- .Net单元测试(三) —— XML数据载体在项目中的应用
- iOS开发中的典型代码-持续更新中~~~
- HDU -- 1869 六度分离 (Floyd)