您的位置:首页 > 其它

Emag eht htiw Em Pleh(POJ 2993)、Help Me with the Game(POJ 2996)模拟题

2013-08-07 16:10 381 查看
Emag eht htiw Em Pleh(POJ 2993)

~题目链接~

http://poj.org/problem?id=2993

输入

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

结果

+---+---+---+---+---+---+---+---+
|.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.|
+---+---+---+---+---+---+---+---+
图示:white:大写字母,顺序从下往上
black:小写字母,顺序从上往下


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>

int flag;
char s[40],map[8][8];

void find1(char str)
{
for(int i=7; i>=0; i--)
for(int j=0; j<8; j++)
if(map[i][j]==str)
{
if(!flag)
flag=1;
else
printf(",");
if(str!='P')
printf("%c",str);
printf("%c%d",j+'a',8-i);
}
}

void find2(char str)
{
for(int i=0; i<8; i++)
for(int j=0; j<8; j++)
if(map[i][j]==str)
{
if(!flag)
flag=1;
else
printf(",");
if(str!='p')
printf("%c",toupper(str));
printf("%c%d",j+'a',8-i);
}
}

int main()
{
gets(s);
for(int i=0; i<8; i++)
{
gets(s);
for(int j=0; j<8; j++)
{
if(isalpha(s[4*(j+1)-2]))
map[i][j]=s[4*(j+1)-2];
}
gets(s);
}
flag=0;
printf("White: ");
find1('K');find1('Q');find1('R');find1('B');find1('N');find1('P');
printf("\n");
flag=0;
printf("Black: ");
find2('k');find2('q');find2('r');find2('b');find2('n');find2('p');
printf("\n");
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: