首页 > 代码库 > Poj 2993 Emag eht htiw Em Pleh

Poj 2993 Emag eht htiw Em Pleh

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,e4Black: 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

CTU Open 2005

3.Method:

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

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

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

4.Code:

 1 #include <iostream> 2 #include <string> 3  4 using namespace std; 5  6 int main() 7 { 8     //freopen("D://input.txt","r",stdin); 9 10     int i,j;11 12     //init output13     string str_out[8 + 9];14     str_out[0] = "+---+---+---+---+---+---+---+---+";15     for(i = 0; i < 8; ++i)16     {17         str_out[i * 2 + 1] = "|";18         for(j = 0; j < 8; ++j)19         {20             if((i + j) % 2 == 0) str_out[i * 2 + 1] += "...";21             else str_out[i * 2 + 1] += ":::";22             str_out[i * 2 + 1] += "|";23         }24         str_out[(i + 1) * 2] = "+---+---+---+---+---+---+---+---+";25     }26 27 28     string str;29 30     //white:31     cin >> str;32     cin >> str;33 34     str = "," + str;35 36     //cout << str << endl;37     int arr_ch[] = {K,Q,R,B,N};38 39     string::size_type str_i;40     for(str_i = 0; str_i != str.size(); ++str_i)41     {42         if(str[str_i] == ,)43         {44             for(i = 0; i < 5; ++i) if(str[str_i + 1] == arr_ch[i]) break;45             if(i < 5)46             {47                 str_out[(8 - (str[str_i + 3] - 0)) * 2 + 1][2 + 4 * (str[str_i + 2] - a)] = arr_ch[i];48             }49             else50             {51                 str_out[(8 - (str[str_i + 2] - 0)) * 2 + 1][2 + 4 * (str[str_i + 1] - a)] = P;52             }        53         }54     }55 56     //black:57     cin >> str;58     cin >> str;59     str = "," + str;60 61     //cout << str << endl;62 63     for(str_i = 0; str_i != str.size(); ++str_i)64     {65         if(str[str_i] == ,)66         {67             for(i = 0; i < 5; ++i) if(str[str_i + 1] == arr_ch[i]) break;68             if(i < 5)69             {70                 str_out[(8 - (str[str_i + 3] - 0)) * 2 + 1][2 + 4 * (str[str_i + 2] - a)] = arr_ch[i] + (a - A);71             }72             else73             {74                 str_out[(8 - (str[str_i + 2] - 0)) * 2 + 1][2 + 4 * (str[str_i + 1] - a)] = p;75             }        76         }77     }78 79     80     for(i = 0; i < 17; ++i) cout << str_out[i] << endl;81 82     //fclose(stdin);83 84     return 0;85 }

 

5.Reference:

Poj 2993 Emag eht htiw Em Pleh