Help Me with the Game
Help Me with the GameCrawling in process... Crawling failed
Description
Input
Output
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 ;
}
随机推荐
- [置顶] iptables 性能 测试
一直研究iptables 性能,这几天刚好有硬件资源,于是发始下手测试iptables NAT 性…… 硬件环境 : 服务器: IBM x3650 ( 4G E5645 6核 12线程) ESXi ...
- mybatis0208 缓存
查询缓存 1.1缓存的意义 数据在磁盘会有一个IO,高并发读取效率就很低,将用户经常查询的数据放在缓存(内存)中,用户去查询数据就不用从磁盘上(关系型数据库数据文件)查询,从缓存中查询,从而提高查询效 ...
- GCC相关的环境变量
介绍GCC在编译阶段和程序运行阶段用到的环境变量. GCC编译时用到的环境变量 GCC编译时用到的变量. C_INCLUDE_PATH GCC编译时查找头文件的目录列表.比如: echo $C_INC ...
- iOS-iPad开发之SplitViewController简单介绍
iOS-iPad开发之SplitViewController简单介绍 SplitViewController图形化创建 SplitViewController可以并列显示两个view,适用于基于nav ...
- mac 下svn降级
mac 手欠 homebrew 安装完成后 brew install svn svn版本更新至1.8.11 公司svn 不支持1.8 需要降级 搜索很多资料 写的比较麻烦 总结出来是先卸载再 ...
- 10.29 morning
WPS转word太丑了 凑合看喽 第二题 [题目描述] 给你两个日期,问这两个日期差了多少毫秒. [输入格式] 两行,每行一个日期,日期格式保证为“YYYY-MM-DD hh:mm:ss ”这种形式. ...
- Android App优化建议(转载)
假如要Google Play上做一个最失败的案例,那最好的秘诀就是界面奇慢无比.耗电.耗内存.接下来就会得到用户的消极评论,最后名声也就臭了.即使你的应用设计精良.创意无限也没用. 耗电或者内存占用等 ...
- 【转】 UINavigationItem UINavigationBar 关系分析
原文:http://blog.csdn.net/luoyeffcs/article/details/16106707 目录 1.关系分析 2.关系综述 3.概念点 4.疑问 1.关系分析 UIBarI ...
- HttpClient的get+post请求使用
啥都不说,先上代码 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReade ...
- Vijos1825 NOI2008 志愿者招募 费用流
Orz ByVoid大神的题解:https://www.byvoid.com/blog/noi-2008-employee/ 学习网络流建图的好题,不难想到线性规划的模型,不过利用模型的特殊性,结合网 ...