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. 23web app实现上下左右滑动

    转载请说明出处:http://blog.csdn.net/wowkk/article/category/1619287 (创意系列) /*最近项目须要苹果电脑,假设您支持学生创业并愿意赞助我们一台,请 ...

  2. Android中GridView拖拽的效果

    最 近看到联想,摩托罗拉等,手机launcher中有个效果,进入mainmenu后,里面的应用程序的图标可以拖来拖去,所以我也参照网上给的代码,写了 一个例子.还是很有趣的,实现的流畅度没有人家的那么 ...

  3. 将html中的br换行符转换为文本输入中的换行符(转)

    PHP中的有个非常好的函数:nl2br(),将文本框中的换行转换为HTML页面的<br />,但是如何实现将html中的<br />换行符转换为文本框中的换行符呢?下面这几个方 ...

  4. 使用AVCaptureSession显示相机预览

    #import <UIKit/UIKit.h> #import <AVFoundation/AVFoundation.h> @interface ViewController ...

  5. 3 - SQL Server 2008 之 使用SQL语句删除约束条件

    基本语法为: ALTER TABLE 表名 DROP CONSTRAINT 约束名1,约束名2…… 如果删除一个约束,不需要逗号后的约束名,如果删除两个及两个以上的约束,必须以逗号隔开. 使用上一节中 ...

  6. URAL 1988 - Planet Ocean Landing【几何&三分答案】

    [题意] 在一个星球(是一个球体)表面有一个飞机(坐标(x1,y1,z1),原点是星球中心),在空中有一个空间站(坐标(x2,y2,z2)),所有值均小于100,现在要使飞机与空间站相遇,飞机的速度是 ...

  7. Java实现对文件的上传下载操作

    通过servlet,实现对文件的上传功能 1.首先创建一个上传UploadHandleServlet ,代码如下: package me.gacl.web.controller; import jav ...

  8. JavaSE、JavaEE、JavaME三者的区别

    1. Java SE(Java Platform,Standard Edition). Java SE 以前称为 J2SE. 它允许开发和部署在桌面.服务器.嵌入式环境和实时环境中使用的 Java 应 ...

  9. HTTP could not register URL http://+:8000/.... Your process does not have access rights to this namespace

    windows 7, Visual Studio 2013 在托管 Windows 服务中承载 WCF 服务时报错: HTTP could not register URL http://+:8000 ...

  10. VisualStudio2013&VS2015内置SQLServer入门 (三)

    关于LocalDB的部署(publish): 使用本机做服务器(目测不可行) 双击项目的Properties-->Publish-->Application Files,你会发现没有.md ...