Help Me with the Game

时间:2021-10-07 04:44:00

Help Me with the GameCrawling in process... Crawling failed

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
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
using namespace std;
struct node
{
int hang;
int lie;
int data;
int jb;
} white[],black[];
int sw(char p)//只是为了让级别好记,好排序
{
if(p=='K' || p=='k') return ;
if(p=='Q' || p=='q') return ;
if(p=='R' || p=='r') return ;
if(p=='B' || p=='b') return ;
if(p=='N' || p=='n') return ;
if(p=='P' || p=='p') return ;
return ;
}
int cmpw(const void*a,const void *b)//这个排序很是坑爹,最初一直没想这样写,结果还是这样,又快又方便
{
if(((node*)a)->jb!=((node*)b)->jb)
return ((node*)a)->jb-((node*)b)->jb;
if(((node*)a)->hang!=((node*)b)->hang)
return ((node*)a)->hang-((node*)b)->hang;
return ((node*)a)->lie-((node*)b)->lie;
}
int cmpb(const void*a,const void *b)
{
if(((node*)a)->jb!=((node*)b)->jb)
return ((node*)a)->jb-((node*)b)->jb;
if(((node*)a)->hang!=((node*)b)->hang)
return ((node*)b)->hang-((node*)a)->hang;
return ((node*)a)->lie-((node*)b)->lie;
}
int main()
{
int wi=,bi=,i;
char ch;
for(i=; i>; i--)
{
scanf("+---+---+---+---+---+---+---+---+\n");
int sum=;
while(scanf("%c",&ch)&&ch!='\n')
{
if('A'<=ch&&ch<='Z')
{
white[wi].hang=i;
white[wi].lie=sum;//明显第几列和“|”的数目挂钩
white[wi].data=ch;
white[wi].jb=sw(ch);
wi++;
}
else if('a'<=ch&&ch<='z')
{
black[bi].hang=i;
black[bi].lie=sum;
black[bi].data=ch;
black[bi].jb=sw(ch);
bi++;
}
else if(ch=='|')//再剩余的字符就不用看了
sum++;
}
}
scanf("+---+---+---+---+---+---+---+---+");
qsort(white,wi,sizeof(node),cmpw);//排序,这个让我纠结了好久,郁闷
qsort(black,bi,sizeof(node),cmpb);
wi--;
bi--;
printf("White: ");//这种坑爹的输出,好吧……只是很长,不复杂
for(i=; i<wi; i++)
{
if(white[i].data!='P')
printf("%c",white[i].data);
printf("%c",white[i].lie+'a'-);
printf("%d,",white[i].hang); }
if(white[i].data!='P')
printf("%c",white[i].data);
printf("%c",white[i].lie+'a'-);
printf("%d\n",white[i].hang);
printf("Black: ");
for(i=; i<bi; i++)
{
if(black[i].data!='p')
printf("%c",black[i].data-);
printf("%c",black[i].lie+'a'-);
printf("%d,",black[i].hang);
}
if(black[i].data!='p')
printf("%c",black[i].data-);
printf("%c",black[i].lie+'a'-);
printf("%d\n",black[i].hang);
return ;
}

随机推荐

  1. Chrome Dev Tools :成为更高效的开发人员

    原文出处 http://blog.jobbole.com/22065/ 实时CSS Style编辑 选择一个Dom,可以对Dom进行编辑和操作,实时修改Css Style, 同时CssStyle可以保 ...

  2. 关于 HTTP 请求头的内容

    HTTP(HyperTextTransferProtocol)即超文本传输协议,目前网页传输的的通用协议.HTTP协议采用了请求/响应模型,浏览器或其他客户端发出请求,服务器给与响应.就整个网络资源传 ...

  3. Java——新IO 通道

    import java.io.File; import java.io.FileOutputStream; import java.nio.ByteBuffer; import java.nio.ch ...

  4. Centos6&period;7下安装配置VPN

    在Vultr上买了台VPS准备做VPN,不贵5刀,位置是日本东京的.ping值在100-200之间,还好算说的过去. Vultr地址 系统选择的Centos6 的版本是6.7 在网上查了查linux下 ...

  5. Maven-改变本地存储仓库位置

    修改 maven 仓库存放位置: 找到 maven 下的 conf 下的 settings.xml 配置文件,假设maven安装在D:\Server目录中.那么配置文件应该在 D:\Server\ma ...

  6. MySQL EER反向建表

    Database > Synchronize Model... Choose Stored Connection Select the Schemata Choose which to upda ...

  7. C&num;Lambda表达式学习日记

    Lambda表达式只是用更简单的方式来写匿名方法,彻底简化了对.NET委托类型的使用. 现在,如果我们要使用泛型 List<> 的 FindAll() 方法,当你从一个集合去提取子集时,可 ...

  8. 「OC」&commat;property &commat;synthesize和id

    一.@property @synthesize关键字 这两个关键字是编译器特性,让Xcode可以自动生成getter和setter. (一)@property 关键字 @property 关键字可以自 ...

  9. raid功能中spanning和striping模式有什么区别&quest;

    RAID 0 又称为Stripe(条带化,串列)或Striping 它代表了所有RAID级别中最高的存储性能.RAID 0提高存储性能的原理是把连续的数据分散到多个磁盘上存取,这样,系统有数据请求就可 ...

  10. SQL varbinary varchar 互转

    --============================================== -- FUNCTION varbin2hexstr -- 将 varbinary 类型的数据转换为 v ...