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. nginx的特点
  2. android XMl 解析神奇xstream 二: 把对象转换成xml
  3. php封装练习
  4. JS 阻止浏览器默认行为和冒泡事件
  5. 简单的说说jsonp
  6. Android系统在超级终端下必会的命令大全(adb shell命令大全)
  7. 《转》15种CSS混合模式让图片产生令人惊艳的效果
  8. Java Hibernate 之连接池详解
  9. uiautomator &lt;一&gt; 编译运行
  10. C陷阱与缺陷代码分析之第2章语法陷阱
  11. A Game of Thrones(18) - Catelyn
  12. The Nerd Factor SPOJ - MYQ5
  13. Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: &#39;L
  14. BZOJ 1370: [Baltic2003]Gang团伙(luogu 1892)(种类并查集)
  15. spring学习1
  16. java几种垃圾收集方法和垃圾收集器
  17. 常用的查询DOM的方法
  18. PostgreSQL 10首个测试版本发布
  19. 【python-opencv】几何变换
  20. COM组件三大接口IUnknown、IClassFactory、IDispatch。

热门文章

  1. [置顶] Codeforces Round #198 (Div. 1)(A,B,C,D)
  2. innodb结构解析工具---innodb_ruby
  3. centos6.4安装flashcache
  4. 使用fastjson前台报406的问题解决方法
  5. windows 与Linux 互传文件
  6. javascript动画效果
  7. 嵌入式css样式,写在当前的文件中
  8. [转]PHP取整函数:ceil,floor,round,intval的区别详细解析
  9. javascript基础学习(二)
  10. 打开自定义链接新窗口(safari JS prompt的坑!)2016.03.08