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的相关讲解

    浏览器chrome Chrome它内部有一个解析器,这个解析器就是解析我们的代码,各个浏览器的内核不一样,所以存在浏览器的兼容.这个内核是一个引擎. 谷歌的内核是webkit 引擎是v8. 客户端的请 ...

  2. 选美?作秀?MES系统的选择更应该从实际出发

    MES选型不是做秀,不是选美. 如今不少企业在信息化推广应用过程中面面求好.追求完美,用意没错,然而在MES开发过程中,软件商不可能将今后各种可能出现的问题考虑周全,不可能将系统做到十全十美.随着系统 ...

  3. nodeJs 报maximum call stack size exceeded js

    先看错误 查了下资料说是什么js堆栈异常,是递归造成的啥的,但我程序里没用到啥递归,整了老半天将collection-repeat换成ng-repeat然后就好啦,具体原因待探讨.

  4. 结对编程作业(java实现)

    项目成员:罗海屏.郑晓婷 一 .Github项目地址:https://github.com/ting9500/GNIT_Second 二.PSP表格 PSP2.1 Personal Software ...

  5. 探秘JVM的底层奥秘

    JVM的简单运行流程:主要将字节码文件加载到JVM的内存中,负责跨平台解释字节码文件到不同的操作系统. JVM的基本结构: 类加载器.执行引擎.运行时数据区域.本地接口 类的装载 加载.连接(验证.准 ...

  6. mysql系列1

    1. mysql数据库的安装步骤如下: [root@mysqltest01 local]# pwd/usr/local [root@mysqltest01 local]# tar -xvf mysql ...

  7. Nginx 高级配置-压缩功能

    Nginx 高级配置-压缩功能 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Nginx压缩相关参数概述 1>.gzip on | off; Nginx支持对指定类型的文 ...

  8. nginx.conf 下日志host.access.log 说明

    位置usr/local/nginx/conf/nginx.conf $server_port 请求端口 $remote_addr 局域网代理IP:如果没同意任何代理的话$remote_addr 就是真 ...

  9. scapy 中sniff指定的数据包并打印指定信息

    在理解这篇文章前可以先看看这两篇文章: https://www.cnblogs.com/liyuanhong/p/10925582.html https://www.cnblogs.com/liyua ...

  10. application platform as a service (aPaaS)

    Application platform as a service (aPaaS) is a cloud service that provides environments for the deve ...