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. C++中的Mat, const Mat, Mat &,Mat &, const Mat &的区别

    Mat, copy传递,不会改变外部变量的Mat. Mat &, reference传递,函数内部修改将会改变外部. const Mat, copy传递,在函数内,不会被修改,也不会影响到外部 ...

  2. 【python+selenium学习】常见错误: 'gbk' codec can't decode byte 0xb0 in position 30

    最近编写的自动化脚本,数据部分使用到了从配置文件中取,即自定义config.ini,但是在读取配置文件的时候却报错了'gbk' codec can't decode byte 0xb0 in posi ...

  3. OO_BLOG4_UML系列学习

    目录 Unit4 作业分析 作业 4-1 UML类图解析器UmlInteraction 作业 4-2 扩展解析器(UML顺序图.UML状态图解析,基本规则验证) 架构设计及OO方法理解的演进 测试理解 ...

  4. redis不能保存bean对象

    可用JSON转为json格式 // 2.3 将用户信息存储在redis中 String memberToJson = JSON.toJSON(member).toString(); 需要maven坐标 ...

  5. NameNode && Secondary NameNode工作机制

    NameNode && Secondary NameNode工作机制 1)工作流程 2)  fsimage和edits NameNode是HDFS的大脑,它维护着整个文件系统的目录树, ...

  6. Odoo报表的report标签和报表格式定义

    转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10826329.html 一:Report标签     report标签可用于定义一条报表记录.属性有: 1) ...

  7. Nginx 核心配置-作为下载服务器配置

    Nginx 核心配置-作为下载服务器配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.无限速版本的下载服务器 1>.查看主配置文件 [root@node101.yinz ...

  8. 性能测试基础---jmeter二次开发

    ·Jmeter的二次开发,常见的有以下几种类型: ·扩展.修改Jmeter已有的组件(源代码) ·扩展.修改Jmeter已有的函数. ·完全自主开发一个新的组件(依赖于Jmeter提供的框架). ·扩 ...

  9. VUE的路由器的总结

    vue的路由器,我们在使用vue进行开发的时候,是必须用到的一个vue自带的组件,下面进行vue经常的操作的一些说明 1.vue-router的安装 在命令行里面使用 cnpm install vue ...

  10. seq2seq模型详解及对比(CNN,RNN,Transformer)

    一,概述 在自然语言生成的任务中,大部分是基于seq2seq模型实现的(除此之外,还有语言模型,GAN等也能做文本生成),例如生成式对话,机器翻译,文本摘要等等,seq2seq模型是由encoder, ...