Help Me with the Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3175   Accepted: 2053

Description

Your task is to read a picture of a chessboard position and print it in the chess notation.

Input

The input consists of an ASCII-art picture of a chessboard with chess pieces on positions described by the input. The pieces of the white player are shown in upper-case letters, while the black player's pieces are lower-case letters. The letters are one of "K" (King), "Q" (Queen), "R" (Rook), "B" (Bishop), "N" (Knight), or "P" (Pawn). The chessboard outline is made of plus ("+"), minus ("-"), and pipe ("|") characters. The black fields are filled with colons (":"), white fields with dots (".").

Output

The output consists of two lines. The first line consists of the string "White: ", followed by the description of positions of the pieces of the white player. The second line consists of the string "Black: ", followed by the description of positions of the pieces of the black player.

The description of the position of the pieces is a comma-separated
list of terms describing the pieces of the appropriate player. The
description of a piece consists of a single upper-case letter that
denotes the type of the piece (except for pawns, for that this
identifier is omitted). This letter is immediatelly followed by the
position of the piece in the standard chess notation -- a lower-case
letter between "a" and "h" that determines the column ("a" is the
leftmost column in the input) and a single digit between 1 and 8 that
determines the row (8 is the first row in the input).

The pieces in the description must appear in the following order:
King("K"), Queens ("Q"), Rooks ("R"), Bishops ("B"), Knights ("N"), and
pawns. Note that the numbers of pieces may differ from the initial
position because of capturing the pieces and the promotions of pawns. In
case two pieces of the same type appear in the input, the piece with
the smaller row number must be described before the other one if the
pieces are white, and the one with the larger row number must be
described first if the pieces are black. If two pieces of the same type
appear in the same row, the one with the smaller column letter must
appear first.

Sample Input

+---+---+---+---+---+---+---+---+
|.r.|:::|.b.|:q:|.k.|:::|.n.|:r:|
+---+---+---+---+---+---+---+---+
|:p:|.p.|:p:|.p.|:p:|.p.|:::|.p.|
+---+---+---+---+---+---+---+---+
|...|:::|.n.|:::|...|:::|...|:p:|
+---+---+---+---+---+---+---+---+
|:::|...|:::|...|:::|...|:::|...|
+---+---+---+---+---+---+---+---+
|...|:::|...|:::|.P.|:::|...|:::|
+---+---+---+---+---+---+---+---+
|:P:|...|:::|...|:::|...|:::|...|
+---+---+---+---+---+---+---+---+
|.P.|:::|.P.|:P:|...|:P:|.P.|:P:|
+---+---+---+---+---+---+---+---+
|:R:|.N.|:B:|.Q.|:K:|.B.|:::|.R.|
+---+---+---+---+---+---+---+---+

Sample Output

White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4
Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6

【题目来源】

CTU Open 2005

http://poj.org/problem?id=2996

【题目大意】
读入一张棋盘。白棋用大写字母表示,黑棋用小写字母表示。
其中各个字母的含义:K(国王)、Q(女王)、R(车),B(主教)、N(骑士)、P(兵)。
小写字母a到h表示列,数字1到8表示行。
输出对应的棋子的名称和坐标。注意:兵(P)不用输出名称。

【题目分析】

题目本来很简单,但是如果方法选的不恰当,再简单的题目也会变得很难,所以说做题还是要将大部分的时间花在思考上,而不是写代码上。

这题就是一个简单的模拟+暴搜,没有任何技巧。

思路清晰,就很容易1A。

我看网上有的人写了260多行,狂晕。

#include<cstdio>
char Map[][]; void find1(char c)
{
for(int i=;i<=;i++)
for(int j=;j<=;j++)
{
if(Map[i][j]==c)
{
if(c>='A'&&c<='Z') printf("%c",c);
else printf("%c",c-);
printf("%c%d,",'a'+j/,i/);
}
}
} void find2(char c)
{
for(int i=;i>=;i--)
for(int j=;j<=;j++)
{
if(Map[i][j]==c)
{
if(c>='A'&&c<='Z') printf("%c",c);
else printf("%c",c-);
printf("%c%d,",'a'+j/,i/);
}
}
} void find_write()
{
find1('K');
find1('Q');
find1('R');
find1('B');
find1('N');
int flag=;
for(int i=;i<=;i++)
for(int j=;j<=;j++)
{
if(Map[i][j]=='P')
{
if(flag)
printf(",%c%d",'a'+j/,i/);
else printf("%c%d",'a'+j/,i/);
flag++;
}
}
puts("");
} void find_black()
{
find2('k');
find2('q');
find2('r');
find2('b');
find2('n');
int flag=;
for(int i=;i>=;i--)
for(int j=;j<=;j++)
{
if(Map[i][j]=='p')
{
if(flag)
printf(",%c%d",'a'+j/,i/);
else printf("%c%d",'a'+j/,i/);
flag++;
}
}
puts("");
} int main()
{
while(scanf("%s",Map[]+)!=EOF)
{
for(int i=;i>=;i--)
scanf("%s",Map[i]+);
printf("White: " );
find_write();
printf("Black: " );
find_black();
}
return ;
}

模拟 + 暴搜 --- Help Me with the Game的更多相关文章

  1. HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

    Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...

  2. 【2019.7.20 NOIP模拟赛 T1】A(A)(暴搜)

    打表+暴搜 这道题目,显然是需要打表的,不过打表的方式可以有很多. 我是打了两个表,分别表示每个数字所需的火柴棒根数以及从一个数字到另一个数字,除了需要去除或加入的火柴棒外,至少需要几根火柴棒. 然后 ...

  3. 【Luogu】P1312Mayan游戏(暴搜)

    题目链接 由于是暴搜题,所以这篇博客只讲怎么优化剪枝,以及一些细节. 模拟消除思路:因为消除可以拆分成小的横条或竖条,而这些条的长度至少为三,所以一块可消除的区域至少会有一个中心点.这里的中心点可以不 ...

  4. 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜

    3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 154[Submit][Status][Discuss] ...

  5. c++20701除法(刘汝佳1、2册第七章,暴搜解决)

    20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有 ...

  6. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

  7. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  8. Sicily1317-Sudoku-位运算暴搜

    最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...

  9. codeforces 339C Xenia and Weights(dp或暴搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Weights Xenia has a set of weig ...

随机推荐

  1. html、css/bootStrap、js/Jquery、ajax与json数据交互总结

    设计个个人网站,利用CSS.JavaScript.HTML5.jQuery库和AJAX等 实现网站各功能模块,下面介绍我设计的网站各大功能模块:  个人简历模块: 包涵个人基本信息(利用CSS的flo ...

  2. Java程序员的魔法杖-Arthas 3.1.2版本发布了

    Arthas已经成为我日常运维.线上排查的必备之品,听说最近更新版本了,今天这篇文章看下又增加了什么新的能力. Arthas是Alibaba开源的Java诊断工具,深受开发者喜爱. Github:ht ...

  3. Centos7配置ssh免密登录群发

    ssh免密登录是客户端发送自己的公钥到服务器.用公钥进行解密,自己生成的私钥进行加密. 首先在客户端查看sshd服务是否启动 [zhiwei@zhiwei1 ~]$ ps -Af|grep sshd; ...

  4. itextpdf中表格中单元格的文字水平垂直居中的设置

    在使用itextpdf中,版本是5.5.6,使用Doucument方式生成pdf时,设置单元格中字体的对齐方式时,发现一些问题,并逐渐找到了解决方式. 给我的经验就是:看官网的例子才能保证代码的效果, ...

  5. 国内加速访问 GitHub

    国内加速访问 GitHub 本文原始地址:https://sitoi.cn/posts/23395.html 中国访问 GitHub 的速度不忍直视,那就叫一个慢! Q: 为什么访问速度会很慢? A: ...

  6. isaster(Comet OJ - Contest #11D题+kruskal重构树+线段树+倍增)

    目录 题目链接 思路 代码 题目链接 传送门 思路 \(kruskal\)重构树\(+\)线段树\(+\)倍增 代码 #include <set> #include <map> ...

  7. iOS开发xib控件删不掉,修改xib运行不发生改变,修改xib不管用

    修改xib控件tag值,颜色,大小,甚至删除发现编译.运行之后效果没改变,用代码修改内容发现管用, 其实只需要clean一下!^_^ 快捷键:shift + command + k

  8. windows 上robot framework 读取sqlite3提示:OperationalError: unable to open database file错误

    原因:路径写的不正确. 正确的写法:'D:/Python27/163/demo.db' 或者 r 'E:\\rf-demos-master\\DatabaseDemo\\demo.db' Connec ...

  9. 微信小程序 vscode 自动保存 保存自动编译 微信开发者工具崩溃

    修改vscode的自动保存延迟时间,将 auto save delay 选项 修改的长一点.

  10. Vue 分页功能伪代码实现

    Vue分页功能的实现 其实分页功能是一个比较简单的demo 后端写好pageNum和pageSize的接口直接传参就是了 // 这里我们假设后端已经写好了 pageNum和pagesize <v ...