Help Me with the Game
2016-07-26 17:35
295 查看
Help Me with the Game
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
Sample Output
直接扫一遍图,吧字母的位置记录下来,分别记录到B 和 W 中。然后拍一下序,之后就是根据K Q R B N P 输出就行了。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
char s[110];
struct node
{
char data;
int x;
int y;
}b[100],w[100];
void get()
{
scanf("%s",s);
}
int cmpw(node a,node b)
{
if(a.x!=b.x)return a.x<b.x;
else return a.y<b.y;
}
int cmpb(node a,node b)
{
if(a.x!=b.x)return a.x>b.x;
else return a.y<b.y;
}
void print(node a[],int n)
{
int i;
for(i=0;i<n;++i)
{
if(a[i].data=='K')
{
printf("K%c%d",a[i].y+'a',a[i].x);
break;
}
}
for(i=0;i<n;++i)
{
if(a[i].data=='Q')
{
printf(",Q%c%d",a[i].y+'a',a[i].x);
break;
}
}
for(i=0;i<n;++i)
{
if(a[i].data=='R')
{
printf(",R%c%d",a[i].y+'a',a[i].x);
}
}
for(i=0;i<n;++i)
{
if(a[i].data=='B')
{
printf(",B%c%d",a[i].y+'a',a[i].x);
}
}
for(i=0;i<n;++i)
{
if(a[i].data=='N')
{
printf(",N%c%d",a[i].y+'a',a[i].x);
}
}
for(i=0;i<n;++i)
{
if(a[i].data=='P')
{
printf(",%c%d",a[i].y+'a',a[i].x);
}
}
}
int main()
{
int i,j;
int cnt1=0,cnt2=0;
for(i=8;i>=1;--i)
{
get();
scanf("%s",s);
int l=strlen(s);
int sum=-1;
for(j=0;j<l;++j)
{
if(islower(s[j]))
{
sum++;
b[cnt1].data=toupper(s[j]);
b[cnt1].x=i;
b[cnt1].y=sum;
cnt1++;
}
else
if(isupper(s[j]))
{
sum++;
w[cnt2].data=s[j];
w[cnt2].x=i;
w[cnt2].y=sum;
cnt2++;
}
if(s[j]==s[j-1]&&s[j]==s[j+1])sum++;
}
}
sort(w,w+cnt2,cmpw);
sort(b,b+cnt1,cmpb);
printf("White: ");
print(w,cnt2);
printf("\n");
printf("Black: ");
print(b,cnt1);
printf("\n");
return 0;
}
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4351 | Accepted: 2740 |
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
直接扫一遍图,吧字母的位置记录下来,分别记录到B 和 W 中。然后拍一下序,之后就是根据K Q R B N P 输出就行了。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
char s[110];
struct node
{
char data;
int x;
int y;
}b[100],w[100];
void get()
{
scanf("%s",s);
}
int cmpw(node a,node b)
{
if(a.x!=b.x)return a.x<b.x;
else return a.y<b.y;
}
int cmpb(node a,node b)
{
if(a.x!=b.x)return a.x>b.x;
else return a.y<b.y;
}
void print(node a[],int n)
{
int i;
for(i=0;i<n;++i)
{
if(a[i].data=='K')
{
printf("K%c%d",a[i].y+'a',a[i].x);
break;
}
}
for(i=0;i<n;++i)
{
if(a[i].data=='Q')
{
printf(",Q%c%d",a[i].y+'a',a[i].x);
break;
}
}
for(i=0;i<n;++i)
{
if(a[i].data=='R')
{
printf(",R%c%d",a[i].y+'a',a[i].x);
}
}
for(i=0;i<n;++i)
{
if(a[i].data=='B')
{
printf(",B%c%d",a[i].y+'a',a[i].x);
}
}
for(i=0;i<n;++i)
{
if(a[i].data=='N')
{
printf(",N%c%d",a[i].y+'a',a[i].x);
}
}
for(i=0;i<n;++i)
{
if(a[i].data=='P')
{
printf(",%c%d",a[i].y+'a',a[i].x);
}
}
}
int main()
{
int i,j;
int cnt1=0,cnt2=0;
for(i=8;i>=1;--i)
{
get();
scanf("%s",s);
int l=strlen(s);
int sum=-1;
for(j=0;j<l;++j)
{
if(islower(s[j]))
{
sum++;
b[cnt1].data=toupper(s[j]);
b[cnt1].x=i;
b[cnt1].y=sum;
cnt1++;
}
else
if(isupper(s[j]))
{
sum++;
w[cnt2].data=s[j];
w[cnt2].x=i;
w[cnt2].y=sum;
cnt2++;
}
if(s[j]==s[j-1]&&s[j]==s[j+1])sum++;
}
}
sort(w,w+cnt2,cmpw);
sort(b,b+cnt1,cmpb);
printf("White: ");
print(w,cnt2);
printf("\n");
printf("Black: ");
print(b,cnt1);
printf("\n");
return 0;
}
相关文章推荐
- String详解, String和CharSequence区别, StringBuilder和StringBuffer的区别 (String系列之1)
- C# WinCE中DataGrid列设置(列宽 列标题等)
- 图片间有空隙的解决方法
- SpringBoot的常用系统变量
- AngularJS 表格
- Linux内核编译过程详解
- Emag eht htiw Em Pleh
- [置顶] Spark源码解读(3)——从集群启动到Job提交
- Android自定义SurfaceView——实现画板功能
- centos discuz论坛环境搭建
- Android UI系列-----长度单位和内外边距
- 糍粑大叔的独游之旅-u3d中2D轮廓的生成(中)
- 合并(序列)流
- Android事件传递机制
- 糍粑大叔的独游之旅-u3d中2D轮廓的生成(中)
- GitHub 中国区前 100 名到底是什么样的人?
- 自定义ViewPager实现图片自动轮播无限循环
- org.apache.ibatis.builder.IncompleteElementException: Could not find result map
- IOS的PickView作为TextField事件
- "session marked for kill " 处理杀不掉的锁,立即释放会话资源