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:
1 #include<iostream> 2 #include<string> 3 using namespace std; 4 struct Point 5 { 6 char a,b,c; 7 } P[10000]; 8 void Init() 9 { 10 int ok=1; 11 for (int i=1; i<=64; i++) 12 { 13 if (ok) P[i].a=P[i].b=P[i].c=‘:‘; 14 else P[i].a=P[i].b=P[i].c=‘.‘; 15 if (i%8) ok=!ok; 16 } 17 } 18 int main() 19 { 20 char x,y; 21 int i,j; 22 string White,Black; 23 string tmp="+---+---+---+---+---+---+---+---+"; 24 getline(cin,White); 25 getline(cin,Black); 26 Init(); 27 for (i=7; i<=White.length()-1; i++) 28 { 29 if (White[i]>=‘A‘&&White[i]<=‘Z‘) 30 { 31 x=White[i+2],y=White[i+1]; 32 P[(x-48-1)*8+(y-‘a‘+1)].b=White[i]; 33 } 34 else if (White[i-1]==‘,‘) 35 { 36 x=White[i+1],y=White[i]; 37 P[(x-48-1)*8+(y-‘a‘+1)].b=‘P‘; 38 } 39 } 40 for (i=7; i<=Black.length()-1; i++) 41 { 42 if (Black[i]>=‘A‘&&Black[i]<=‘Z‘) 43 { 44 x=Black[i+2],y=Black[i+1]; 45 P[(x-48-1)*8+(y-‘a‘+1)].b=Black[i]+32; 46 } 47 else if (Black[i-1]==‘,‘) 48 { 49 x=Black[i+1],y=Black[i]; 50 P[(x-48-1)*8+(y-‘a‘+1)].b=‘p‘; 51 } 52 } 53 cout<<tmp<<endl; 54 for (i=8; i>=1; i--) 55 { 56 cout<<‘|‘; 57 for (j=1; j<=8; j++) 58 cout<<P[(i-1)*8+j].a<<P[(i-1)*8+j].b<<P[(i-1)*8+j].c<<‘|‘; 59 cout<<endl; 60 cout<<tmp<<endl; 61 } 62 return 0; 63 }
POJ2993——Emag eht htiw Em Pleh,布布扣,bubuko.com
POJ2993——Emag eht htiw Em Pleh
原文:http://www.cnblogs.com/Enumz/p/3765335.html