POJ2993——Emag eht htiw Em Pleh(字符串处理+排序)

Emag eht htiw Em Pleh

Description
This problem is a reverse case of the problem 2996. You are given the output of the problem H and your task is to find the corresponding input.
Input
according to output of problem 2996.
Output
according to input of problem 2996.
Sample Input
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
Sample Output

+---+---+---+---+---+---+---+---+
|.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.|
+---+---+---+---+---+---+---+---+
题目大意:POJ2996的反向。输入2996的输出,输出2996的输入。
解题思路:
    1.定义结构体存每个格子的状态
    2.初始化结构体数组为“:::”||“...”    
    3.读取字符串,根据数据改变结构体的第二个变量
    4.格式输出
Code:
 #include<iostream>
#include<string>
using namespace std;
struct Point
{
char a,b,c;
} P[];
void Init()
{
int ok=;
for (int i=; i<=; i++)
{
if (ok) P[i].a=P[i].b=P[i].c=':';
else P[i].a=P[i].b=P[i].c='.';
if (i%) ok=!ok;
}
}
int main()
{
char x,y;
int i,j;
string White,Black;
string tmp="+---+---+---+---+---+---+---+---+";
getline(cin,White);
getline(cin,Black);
Init();
for (i=; i<=White.length()-; i++)
{
if (White[i]>='A'&&White[i]<='Z')
{
x=White[i+],y=White[i+];
P[(x--)*+(y-'a'+)].b=White[i];
}
else if (White[i-]==',')
{
x=White[i+],y=White[i];
P[(x--)*+(y-'a'+)].b='P';
}
}
for (i=; i<=Black.length()-; i++)
{
if (Black[i]>='A'&&Black[i]<='Z')
{
x=Black[i+],y=Black[i+];
P[(x--)*+(y-'a'+)].b=Black[i]+;
}
else if (Black[i-]==',')
{
x=Black[i+],y=Black[i];
P[(x--)*+(y-'a'+)].b='p';
}
}
cout<<tmp<<endl;
for (i=; i>=; i--)
{
cout<<'|';
for (j=; j<=; j++)
cout<<P[(i-)*+j].a<<P[(i-)*+j].b<<P[(i-)*+j].c<<'|';
cout<<endl;
cout<<tmp<<endl;
}
return ;
}
上一篇:骨灰级玩家体验带你测试体验天使纪元OL折扣端


下一篇:java生成带html样式的word文件