1.Link:
http://poj.org/problem?id=2996
2.Content:
Help Me with the Game
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3500 Accepted: 2245 Description
Your task is to read a picture of a chessboard position and print it in the chess notation.Input
The input consists of an ASCII-art picture of a chessboard with chess pieces on positions described by the input. The pieces of the white player are shown in upper-case letters, while the black player's pieces are lower-case letters. The letters are one of "K" (King), "Q" (Queen), "R" (Rook), "B" (Bishop), "N" (Knight), or "P" (Pawn). The chessboard outline is made of plus ("+"), minus ("-"), and pipe ("|") characters. The black fields are filled with colons (":"), white fields with dots (".").Output
The output consists of two lines. The first line consists of the string "White: ", followed by the description of positions of the pieces of the white player. The second line consists of the string "Black: ", followed by the description of positions of the pieces of the black player.
The description of the position of the pieces is a comma-separated list of terms describing the pieces of the appropriate player. The description of a piece consists of a single upper-case letter that denotes the type of the piece (except for pawns, for that this identifier is omitted). This letter is immediatelly followed by the position of the piece in the standard chess notation -- a lower-case letter between "a" and "h" that determines the column ("a" is the leftmost column in the input) and a single digit between 1 and 8 that determines the row (8 is the first row in the input).
The pieces in the description must appear in the following order: King("K"), Queens ("Q"), Rooks ("R"), Bishops ("B"), Knights ("N"), and pawns. Note that the numbers of pieces may differ from the initial position because of capturing the pieces and the promotions of pawns. In case two pieces of the same type appear in the input, the piece with the smaller row number must be described before the other one if the pieces are white, and the one with the larger row number must be described first if the pieces are black. If two pieces of the same type appear in the same row, the one with the smaller column letter must appear first.Sample Input
+---+---+---+---+---+---+---+---+ |.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.| +---+---+---+---+---+---+---+---+Sample Output
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,h6Source
3.Method:
模拟题,输入输出麻烦,最好一部部增加格式,来调整,不然一开始考虑全部的话很容易混乱
4.Code:
1 #include <iostream> 2 #include <string> 3 #include <cstring> 4 5 using namespace std; 6 7 struct Point_c 8 { 9 char name; 10 char p_ch; 11 char p_num; 12 }; 13 14 const char name_c[] = {'K','Q','R','R','B','B','N','N','P','P','P','P','P','P','P','P', 15 'k','q','r','r','b','b','n','n','p','p','p','p','p','p','p','p'}; 16 const int num_c = 32; 17 18 19 20 int main() 21 { 22 //freopen("D://input.txt","r",stdin); 23 24 int i,j,k; 25 char p_ch[num_c]; 26 char p_num[num_c]; 27 28 //cout << str << endl; 29 memset(p_ch,0,sizeof(char) * num_c); 30 memset(p_num,0,sizeof(char) * num_c); 31 32 string *arr_str = new string[8]; 33 string str; 34 for(i = 0; i < 8; ++i) 35 { 36 cin >> str; 37 cin >> arr_str[i]; 38 } 39 cin >> str; 40 41 //for(i = 0; i < 8; ++i) cout << arr_str[i] << endl; 42 43 44 for(i = 7; i >= 0; --i) 45 { 46 for(j = 0; j < 8; ++j) 47 { 48 for(k = 0; k < 16; ++k) 49 { 50 if(name_c[k] == arr_str[i][2 + 4 * j] && p_ch[k] == 0) 51 { 52 p_ch[k] = j + 'a'; 53 p_num[k] = (8 - i) + '0'; 54 break; 55 } 56 } 57 } 58 } 59 60 for(i = 0; i < 8; ++i) 61 { 62 for(j = 0; j < 8; ++j) 63 { 64 for(k = 16; k < 32; ++k) 65 { 66 if(name_c[k] == arr_str[i][2 + 4 * j] && p_ch[k] == 0) 67 { 68 p_ch[k] = j + 'a'; 69 p_num[k] = (8 - i) + '0'; 70 break; 71 } 72 } 73 } 74 } 75 76 int flag = 0; 77 78 cout << "White: "; 79 for(k = 0; k < 8; ++k) if(p_ch[k] != 0) 80 { 81 if(p_ch[k] != 0) 82 { 83 if(flag) cout << ","; 84 else flag = 1; 85 cout << name_c[k] << p_ch[k] << p_num[k]; 86 } 87 } 88 for(k = 8; k < 16; ++k) 89 { 90 if(p_ch[k] != 0) 91 { 92 if(flag) cout << ","; 93 else flag = 1; 94 cout << p_ch[k] << p_num[k]; 95 } 96 97 } 98 cout << endl; 99 100 flag = 0; 101 cout << "Black: "; 102 for(k = 16; k < 24; ++k) if(p_ch[k] != 0) 103 { 104 if(p_ch[k] != 0) 105 { 106 if(flag) cout << ","; 107 else flag = 1; 108 cout << (char)(name_c[k] + ('K' - 'k')) << p_ch[k] << p_num[k]; 109 } 110 111 } 112 for(k = 24; k < 32; ++k) 113 { 114 if(p_ch[k] != 0) 115 { 116 if(flag) cout << ","; 117 else flag = 1; 118 cout << p_ch[k] << p_num[k]; 119 } 120 } 121 cout << endl; 122 123 delete [] arr_str; 124 125 return 0; 126 }
5.Reference: