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. delphi实现窗体闪烁功能

    delphi实现窗体闪烁功能 以前做窗口闪动时都没有考虑到让任务栏上的按钮闪动的问题, 现在一个客户需要任务栏按钮闪动,发现以前使用的flashwindow不能达到要求了, 查找了一下,找到flash ...

  2. js执行上下文栈和变量对象

    JavaScript执行上下文栈和变量对象 JS是单线程的语言,执行顺序肯定是顺序执行,但是JS 引擎并不是一行一行地分析和执行程序,而是一段一段地分析执行,会先进行编译阶段然后才是执行阶段. 例子一 ...

  3. day 48

    目录 js BOM(浏览器对象模型) window对象 window子对象 弹出框 计时事件 DOM(文档对象模型) 查找标签 节点操作 事件 常用事件 绑定方式 jQuery jQuery介绍 jQ ...

  4. vue.js 打包时出现空白页和路径错误

    vue-cli输入命令:npm  run  build 即可打包vue.js的项目 打包出来后项目中就会多了一个文件夹dist,下图为我们打包过后的项目 我们直接运行打包后的文件夹中的index.ht ...

  5. AHB总线协议(二)

    下图是8拍回环字突发传输:地址将在 32 字节边界处回环因此地址 0x3C 之后的地址是 0x20. 下图是8增量半字突发传输,所以地址每次增加 2 个字节并且突发在递增因此地址连续增加通过了 16 ...

  6. Spark GraphX图算法应用【分区策略、PageRank、ConnectedComponents,TriangleCount】

    一.分区策略 GraphX采用顶点分割的方式进行分布式图分区.GraphX不会沿着边划分图形,而是沿着顶点划分图形,这可以减少通信和存储的开销.从逻辑上讲,这对应于为机器分配边并允许顶点跨越多台机器. ...

  7. 定时任务突然中止,告警:Thread starvation or clock leap detected

    1.背景 定时任务告警信息如下: 02:38:24.112 [HikariPool-1 housekeeper] WARN  com.zaxxer.hikari.pool.HikariPool - H ...

  8. sqlserver清空删除日志

    USE [lzdxdb] GO ALTER DATABASE lzdxdb SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE lzdxdb SET ...

  9. Python基础(一)--变量、注释、文件头

    一.变量 1.什么是变量 变量是变化的量,用来保存程序执行的状态以及状态的变化 2.变量定义规范 #1. 变量名只能是:字母.数字或下划线的任意组合 #2. 变量名的第一个字符不能是数字 #3. 关键 ...

  10. OpenSSL 下载和私钥证书、CERTIFICATE证书生成

    openssl 是生成私钥和公钥证书的重要工具. Windows如何安装OpenSSL: 官网:https://www.openssl.org/community/mailinglists.html  ...