Emag eht htiw Em Pleh--POJ 2993

1、题目类型:模拟题。

2、解题思路:(1)将输入的棋盘分布转换为map[][];(2)根据map[][]相应输出即可。

3、注意事项:输入中对于Q-q、K-k的处理。

4、实现方法:

#include<iostream>
#include
<string>
#include
<cmath>
using namespace std;

char map[10][10];

void Init()
{
string str1,str2;
int k,j;
for(j=1;j<=8;j++)
for( k=1;k<=8;k++)
map[j][k]
='#';
for(int i=0;i<2;i++)
{
cin
>>str1>>str2;
for(int j=0;j<str2.length();j++)
{
if(str2[j]>='A'&&str2[j]<='Z')
{
if(i==0)
map[
9-(str2[j+2]-'0')][str2[j+1]-'a'+1]=str2[j];
else
map[
9-(str2[j+2]-'0')][str2[j+1]-'a'+1]=str2[j]+('a'-'A');
j
+=2;
continue;
}
if(str2[j]>='a'&&str2[j]<='z')
{
if(i==0)
map[
9-(str2[j+1]-'0')][(str2[j]-'a'+1)]='P';
else
map[
9-(str2[j+1]-'0')][(str2[j]-'a'+1)]='p';
j
+=1;
continue;
}
}
}
}

void Solve()
{
int i,j;
for(i=1;i<=16;i++)
{
if(i%2)
{
cout
<<'+';
for(j=1;j<=8;j++)
cout
<<"---+";
cout
<<endl;
}
else
{
cout
<<'|';
if(i/2%2)
{
for(j=1;j<=8;j++)
{
if(j%2)
{
cout
<<'.';
if(map[i/2][j]!='#')
cout
<<map[i/2][j];
else
cout
<<'.';
cout
<<'.';
cout
<<'|';
}
else
{
cout
<<':';
if(map[i/2][j]!='#')
cout
<<map[i/2][j];
else
cout
<<':';
cout
<<':';
cout
<<'|';
}
}
cout
<<endl;
}
else
{
for(j=1;j<=8;j++)
{
if(j%2==0)
{
cout
<<'.';
if(map[i/2][j]!='#')
cout
<<map[i/2][j];
else
cout
<<'.';
cout
<<'.';
cout
<<'|';
}
else
{
cout
<<':';
if(map[i/2][j]!='#')
cout
<<map[i/2][j];
else
cout
<<':';
cout
<<':';
cout
<<'|';
}
}
cout
<<endl;
}
}
}
cout
<<'+';
for(j=1;j<=8;j++)
cout
<<"---+";
cout
<<endl;
}

int main()
{
Init();
Solve();
return 0;
}

 

posted @ 2010-08-19 17:19  勇泽  阅读(239)  评论(0编辑  收藏  举报