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. 经典SQL语句大全之基础

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname 3.说明:备份sql server--- 创建 ...

  2. ROS中Mangle解析

    http://blog.csdn.net/bluecy/article/details/8192307

  3. 虚拟化技术性能总结:Zones, KVM, Xen

    [译]虚拟化技术性能总结:Zones, KVM, Xen 时间 2014-04-29 16:52:44  Babyfacer_陈晓炜 原文  http://blog.csdn.net/babyface ...

  4. [转] JavaScript 和事件

    与浏览器进行交互的时候浏览器就会触发各种事件.比如当我们打开某一个网页的时候,浏览器加载完成了这个网页,就会触发一个 load 事件:当我们点击页面中的某一个“地方”,浏览器就会在那个“地方”触发一个 ...

  5. block没那么难(一):block的实现

    本系列博文总结自<Pro Multithreading and Memory Management for iOS and OS X with ARC> block 顾名思义就是代码块,将 ...

  6. oracle数组定义与使用

    定义固定长度的一维数组 type type_array is varray(10) of varchar2(20); 1.varray(10)表示定义长度为10的数组 2.varchar2(20)表示 ...

  7. Eclipse配置使用web.xml

    为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/3792664.html ...

  8. Android常用组件【转】

    UI相关 图片 Android-Universal-Image-Loader:com.nostra13.universalimageloader:异步加载.缓存.显示图片 ImageLoader:co ...

  9. Datum Form Goole Android

    1. <TurboChargeYourUI-How to make your AndroidUI fast and efficient> 2. <The World of List ...

  10. Android之提交数据到服务端方法简单封装

    在Android应用中,除了单机版的应用,其余的应用免不了需要频繁地与服务端进行数据交互,如果每一种方法都独立写一段代码,那会造成代码大量重复,冗余,这不是我们所希望的,所以我们可以对其进行一些封装, ...