Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

Submit Status

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

给了一个固定大小的棋盘,要求输出黑白棋子的位置,本身题目不是很难,这种题目恶心在于要注意的地方很多:

1.白棋子是大写字母,黑棋子是小写字母。

2.棋盘的列是从左边开始是a一直到h,行驶从下面开始算1到上面的8。

3.白棋子输出是按照字母优先顺序,黑棋子输出是按照数字优先顺序。

4.本来到这里已经很恶心了,结果还有更奸诈的。。。那就是棋盘上的棋子数量是不固定的,不一定非得是这32个棋子,也是因为这个原因WA了一次。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; char k_c[70],q_c[70],r_c[70],b_c[70],n_c[70],p_c[70],K_c[70],Q_c[70],R_c[70],B_c[70],N_c[70],P_c[70]; int k_y[70],q_y[70],r_y[70],b_y[70],n_y[70],p_y[70],K_y[70],Q_y[70],R_y[70],B_y[70],N_y[70],P_y[70]; string temp,test[20];
int i,j,flag;
int k_num,q_num,r_num,b_num,n_num,p_num,K_num,Q_num,R_num,B_num,N_num,P_num; int main()
{
//freopen("i.txt","r",stdin);
//freopen("o.txt","w",stdout); k_num=1;q_num=1;r_num=1;b_num=1;n_num=1;p_num=1;K_num=1;Q_num=1;R_num=1;B_num=1;N_num=1;P_num=1; cin>>temp;
for(i=1;i<=8;i++)
{
cin>>test[i];
cin>>temp; for(j=2;j<=30;j=j+4)
{
if(test[i][j]=='r')
{
r_c[r_num]='a'+(j/4);
r_y[r_num]=9-i;
r_num++;
}
else if(test[i][j]=='b')
{
b_c[b_num]='a'+(j/4);
b_y[b_num]=9-i;
b_num++;
}
else if(test[i][j]=='k')
{
k_c[k_num]='a'+(j/4);
k_y[k_num]=9-i;
k_num++;
}
else if(test[i][j]=='q')
{
q_c[q_num]='a'+(j/4);
q_y[q_num]=9-i;
q_num++;
}
else if(test[i][j]=='n')
{
n_c[n_num]='a'+(j/4);
n_y[n_num]=9-i;
n_num++;
}
else if(test[i][j]=='p')
{
p_c[p_num]='a'+(j/4);
p_y[p_num]=9-i;
p_num++;
}
}
}
for(i=8;i>=1;i--)
{
for(j=2;j<=30;j=j+4)
{
if(test[i][j]=='R')
{
R_c[R_num]='a'+(j/4);
R_y[R_num]=9-i;
R_num++;
}
else if(test[i][j]=='B')
{
B_c[B_num]='a'+(j/4);
B_y[B_num]=9-i;
B_num++;
}
else if(test[i][j]=='K')
{
K_c[K_num]='a'+(j/4);
K_y[K_num]=9-i;
K_num++;
}
else if(test[i][j]=='Q')
{
Q_c[Q_num]='a'+(j/4);
Q_y[Q_num]=9-i;
Q_num++;
}
else if(test[i][j]=='N')
{
N_c[N_num]='a'+(j/4);
N_y[N_num]=9-i;
N_num++;
}
else if(test[i][j]=='P')
{
P_c[P_num]='a'+(j/4);
P_y[P_num]=9-i;
P_num++;
}
}
} flag=1;
cout<<"White: ";
for(i=1;i<K_num;i++)
{
if(flag)
{
flag=0;
cout<<"K"<<K_c[i]<<K_y[i];
}
else
{
cout<<",K"<<K_c[i]<<K_y[i];
}
}
for(i=1;i<Q_num;i++)
{
if(flag)
{
flag=0;
cout<<"Q"<<Q_c[i]<<Q_y[i];
}
else
{
cout<<",Q"<<Q_c[i]<<Q_y[i];
}
}
for(i=1;i<R_num;i++)
{
if(flag)
{
flag=0;
cout<<"R"<<R_c[i]<<R_y[i];
}
else
{
cout<<",R"<<R_c[i]<<R_y[i];
}
}
for(i=1;i<B_num;i++)
{
if(flag)
{
flag=0;
cout<<"B"<<B_c[i]<<B_y[i];
}
else
{
cout<<",B"<<B_c[i]<<B_y[i];
}
}
for(i=1;i<N_num;i++)
{
if(flag)
{
flag=0;
cout<<"N"<<N_c[i]<<N_y[i];
}
else
{
cout<<",N"<<N_c[i]<<N_y[i];
}
}
for(i=1;i<P_num;i++)
{
if(flag)
{
flag=0;
cout<<P_c[i]<<P_y[i];
}
else
{
cout<<","<<P_c[i]<<P_y[i];
}
}
cout<<endl; flag=1;
cout<<"Black: ";
for(i=1;i<k_num;i++)
{
if(flag)
{
flag=0;
cout<<"K"<<k_c[i]<<k_y[i];
}
else
{
cout<<",K"<<k_c[i]<<k_y[i];
}
}
for(i=1;i<q_num;i++)
{
if(flag)
{
flag=0;
cout<<"Q"<<q_c[i]<<q_y[i];
}
else
{
cout<<",Q"<<q_c[i]<<q_y[i];
}
}
for(i=1;i<r_num;i++)
{
if(flag)
{
flag=0;
cout<<"R"<<r_c[i]<<r_y[i];
}
else
{
cout<<",R"<<r_c[i]<<r_y[i];
}
}
for(i=1;i<b_num;i++)
{
if(flag)
{
flag=0;
cout<<"B"<<b_c[i]<<b_y[i];
}
else
{
cout<<",B"<<b_c[i]<<b_y[i];
}
}
for(i=1;i<n_num;i++)
{
if(flag)
{
flag=0;
cout<<"N"<<n_c[i]<<n_y[i];
}
else
{
cout<<",N"<<n_c[i]<<n_y[i];
}
}
for(i=1;i<p_num;i++)
{
if(flag)
{
flag=0;
cout<<p_c[i]<<p_y[i];
}
else
{
cout<<","<<p_c[i]<<p_y[i];
}
}
cout<<endl; return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 2996:Help Me with the Game的更多相关文章

  1. 模拟 POJ 2996 Help Me with the Game

    题目地址:http://poj.org/problem?id=2996 /* 题意:给出白方和黑方的棋子和对应的坐标,输出该副棋盘的样子 模拟题 + 结构体排序:无算法,switch区分读入的字符,按 ...

  2. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  3. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  4. poj 2996 Help Me with the Game(模拟)

    题目:http://poj.org/problem?id=2996 题意:给出 棋盘 情况 输出 白棋 和 黑棋在 棋盘上的 白棋为大写字母 黑棋为小写字母 棋盘 左下点为原点(1,a) 输出 是 按 ...

  5. POJ 1459:Power Network(最大流)

    http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...

  6. POJ 3436:ACM Computer Factory(最大流记录路径)

    http://poj.org/problem?id=3436 题意:题意很难懂.给出P N.接下来N行代表N个机器,每一行有2*P+1个数字 第一个数代表容量,第2~P+1个数代表输入,第P+2到2* ...

  7. POJ 2195:Going Home(最小费用最大流)

    http://poj.org/problem?id=2195 题意:有一个地图里面有N个人和N个家,每走一格的花费是1,问让这N个人分别到这N个家的最小花费是多少. 思路:通过这个题目学了最小费用最大 ...

  8. POJ 3281:Dining(最大流)

    http://poj.org/problem?id=3281 题意:有n头牛,f种食物,d种饮料,每头牛有fnum种喜欢的食物,dnum种喜欢的饮料,每种食物如果给一头牛吃了,那么另一个牛就不能吃这种 ...

  9. POJ 3580:SuperMemo(Splay)

    http://poj.org/problem?id=3580 题意:有6种操作,其中有两种之前没做过,就是Revolve操作和Min操作.Revolve一开始想着一个一个删一个一个插,觉得太暴力了,后 ...

随机推荐

  1. SpringBoot集成百度UEditor图片上传后直接访问404解决办法

    SpringBoot项目上传图片一般是上传至远程服务器存储,开发过程中可能会上传至当前项目的某个静态目录中,此时就会遇到这个问题,文件在上传之后直接访问并不能被访问到,必须重新加载项目. 首先分析一下 ...

  2. 多选按钮CheckBox

    main.xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...

  3. Tomcat+JSP经典配置实例

    经常看到jsp的初学者问tomcat下如何配置jsp.servlet和bean的问题,于是总结了一下如何tomcat下配置jsp.servlet和ben,希望对那些初学者有所帮助. 一.开发环境配置 ...

  4. 吴裕雄--天生自然JAVA面向对象高级编程学习笔记:接口的基本实现

    interface A{ // 定义接口A public static final String AUTHOR = "李兴华" ; // 全局常量 public abstract ...

  5. chart 模板【转】

    Helm 通过模板创建 Kubernetes 能够理解的 YAML 格式的资源配置文件,我们将通过例子来学习如何使用模板. 以 templates/secrets.yaml 为例: 从结构看,文件的内 ...

  6. 学习Linux系统永远都不晚

    作为一名机械专业毕业的学生,两年的工作经历实实在在地教会了我如何认清现实,让当初那个对机械行业无比憧憬的少年明白了自己选择的路有多艰难.由于我的父母都是工人,所以我比其他同龄人能更早地接触到工业的魅力 ...

  7. Windows 10长脸了!

    Windows 10一直毁誉参半,但是在微软的持续升级完善之下,同时随着时间的流逝,已经顺利成为全球第一大桌面操作系统,并开始逐渐甩开Windows 7,全球设备安装量已经达到约8亿部. 根据最新的S ...

  8. 第1节 HUE:14、15、16、hue与hdfs、yarn集群、hive、impala、mysql的整合

    3.hue与其他框架的集成 3.1.hue与hadoop的HDFS以及yarn集成 第一步:更改所有hadoop节点的core-site.xml配置 记得更改完core-site.xml之后一定要重启 ...

  9. upper_bound()和low_bound函数的基本使用和理解(转载,已获博主授权)

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/sdz20172133/article/details/80101838 前提:一个非降序列!!!!! ...

  10. linux 下office软件推荐

    概述 最近想使用LINUX下搭建服务器,所以查找一些需要用的软件. linux下最好的office解决办法 其实因为我是不怎么使用office的,我也不知道不同office有什么不一样,直到有一次写奖 ...