Poj 2993 Emag eht htiw Em Pleh

时间:2022-10-13 05:11:23

1.Link:

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

2.Content:

Emag eht htiw Em Pleh
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2801   Accepted: 1861

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.|
+---+---+---+---+---+---+---+---+

Source

3.Method:

模拟题,我的方法是想把棋盘初始化好,然后再往里面添棋子

由于很简单,就没有把white和black统一为一种情况,代码不怎么精简

不过对于水题,已经足够了

4.Code:

 #include <iostream>
#include <string> using namespace std; int main()
{
//freopen("D://input.txt","r",stdin); int i,j; //init output
string str_out[ + ];
str_out[] = "+---+---+---+---+---+---+---+---+";
for(i = ; i < ; ++i)
{
str_out[i * + ] = "|";
for(j = ; j < ; ++j)
{
if((i + j) % == ) str_out[i * + ] += "...";
else str_out[i * + ] += ":::";
str_out[i * + ] += "|";
}
str_out[(i + ) * ] = "+---+---+---+---+---+---+---+---+";
} string str; //white:
cin >> str;
cin >> str; str = "," + str; //cout << str << endl;
int arr_ch[] = {'K','Q','R','B','N'}; string::size_type str_i;
for(str_i = ; str_i != str.size(); ++str_i)
{
if(str[str_i] == ',')
{
for(i = ; i < ; ++i) if(str[str_i + ] == arr_ch[i]) break;
if(i < )
{
str_out[( - (str[str_i + ] - '')) * + ][ + * (str[str_i + ] - 'a')] = arr_ch[i];
}
else
{
str_out[( - (str[str_i + ] - '')) * + ][ + * (str[str_i + ] - 'a')] = 'P';
}
}
} //black:
cin >> str;
cin >> str;
str = "," + str; //cout << str << endl; for(str_i = ; str_i != str.size(); ++str_i)
{
if(str[str_i] == ',')
{
for(i = ; i < ; ++i) if(str[str_i + ] == arr_ch[i]) break;
if(i < )
{
str_out[( - (str[str_i + ] - '')) * + ][ + * (str[str_i + ] - 'a')] = arr_ch[i] + ('a' - 'A');
}
else
{
str_out[( - (str[str_i + ] - '')) * + ][ + * (str[str_i + ] - 'a')] = 'p';
}
}
} for(i = ; i < ; ++i) cout << str_out[i] << endl; //fclose(stdin); return ;
}

5.Reference: