poj 2996 Help Me with the Game
题意: 给你一个图表,表内大写的“k,q,b,r,n,p”表示白,小写的表黑;制表的最后一行为1,第一列为A,要求输出白和黑的字母位置,按其要求的顺序。(白:先按类型K>Q>R>B>N>P,从下行往上行,从左列往右列;黑:先按类型K>Q>R>B>N>P,从上行往下行,从左列往右列;)
题解: 没啥意思的模拟题,二维数组处理出表,然后按顺序查找就好了,锻炼下代码能力。。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 100;
char p[N][N];
char s[6] = {'K','Q','R','B','N','P'};
int have,m;
void print1(char x)
{
for(int i = 16; i >= 0; i--)
{
if(i%2)
{
int id = 0;
for(int j = 0; j < m; j++)
{
if(p[i][j] == '|')
id++;
else if(p[i][j] == x)
{
if(!have)
have++;
else
printf(",");
if(x != 'P')
printf("%c",x);
printf("%c%d",id+'a'-1,8-i/2);
}
}
}
}
}
void print2(char x)
{
for(int i = 0; i <= 16 ; i++)
{
if(i%2)
{
int id = 0;
for(int j = 0; j < m; j++)
{
if(p[i][j] == '|')
id++;
else if(p[i][j] == x)
{
if(!have)
have++;
else
printf(",");
if(x != 'p')
printf("%c",x-32);
printf("%c%d",id+'a'-1,8-i/2);
}
}
}
}
}
int main()
{
for(int i = 0; i < 17; i++)
scanf("%s",p[i]);
m = strlen(p[0]);
printf("White: ");
have = 0;
for(int i = 0; i < 6; i++)
print1(s[i]);
puts("");
printf("Black: ");
have = 0;
for(int i = 0; i < 6; i++)
print2(s[i]+32);
puts("");
return 0;
}