Simulation of poj 2996 & 2993 chess Layout

Source: Internet
Author: User

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 (partition t 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 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.
Poj2993:

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.|+---+---+---+---+---+---+---+---+
Code:
# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; char Q [10], W [100]; char E [10], R [100]; char white [12] = {'k', 'Q', 'R', 'B', 'n', 'P '}; char black [12] = {'k', 'Q', 'R', 'B', 'n', 'P'}; char map1 [18] [35]; int S1, S2; int main () {int I, j; for (I = 1; I <= 17; I ++) // initialize the map for (j = 1; j <= 33; j ++) {if (I % 2 = 1 & J % 4 = 1) map1 [I] [J] = '+ '; else if (I % 2 = 1) map1 [I] [J] = '-'; else if (I % 2 = 0 & J % 4 = 1) map1 [I] [J] = '|'; El Se if (I % 4 = 2 & (double) (J % 8)/4 <= 1 & J % 8! = 0) map1 [I] [J] = '. '; else if (I % 4 = 0 & (double) (J % 8)/4> 1 | j % 8 = 0 )) map1 [I] [J] = '. '; else map1 [I] [J] =': ';} For (int K = 1; k <= 2; k ++) // two rows of input {scanf ("% S % s", Q, W); S1 = strlen (w); If (Q [0] = 'W ') {for (I = 0; I <= 5; I ++) for (j = 0; j <= S1; j ++) {If (W [J] = white [I]) map1 [2 * (9-W [J + 2] + '0')] [4 * (W [J + 1]-'A') + 3] = white [I]; If (W [J] = ', '& W [J + 1]> 96) map1 [2 * (9-W [J + 2] + '0')] [4 * (W [J + 1]-'A') + 3] = 'P';} If (Q [0] = 'B ') {for (I = 0; I <= 5; I ++) for (j = 0; j <= S1; j ++) {If (W [J] = white [I]) map1 [2 * (9-W [J + 2] + '0')] [4 * (W [J + 1]-'A') + 3] = black [I]; If (W [J] = ', '& W [J + 1]> 96) map1 [2 * (9-W [J + 2] + '0')] [4 * (W [J + 1]-'A') + 3] = 'P' ;}}for (I = 1; I <= 17; I ++) {for (j = 1; j <= 33; j ++) cout <map1 [I] [J]; cout <Endl ;} return 0 ;}


Poj2996:

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,e4Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
Code:
# Include <iostream> # include <cstdio> using namespace STD; char black [6] = {'k', 'Q', 'R', 'B', 'n ', 'P'}; char white [6] = {'k', 'Q', 'R', 'B', 'n', 'P'}; int main () {int S1, S2; int I, j, k; char map1 [18] [34]; S1 = S2 = 0; for (I = 1; I <= 17; I ++) for (j = 1; j <= 33; j ++) {CIN> map1 [I] [J]; if (map1 [I] [J] = 'P') // This is to not output the last comma... S1 ++; If (map1 [I] [J] = 'P') S2 ++;} cout <"WHITE:"; for (k = 0; k <6; k ++) for (I = 17; I> = 1; I --) for (j = 1; j <= 33; j ++) {if (I % 2 = 0 & J % 4 = 3 & K <= 4) if (map1 [I] [J] = black [k]) {printf ("% C % d,", black [K], 'A' + (J + 1)/4-1, 9-I/2 );} if (k = 5 & I % 2 = 0 & J % 4 = 3) if (map1 [I] [J] = 'P ') {S1 --; If (S1 = 0) {printf ("% C % d \ n", 'A' + (J + 1) /4-1, 9-I/2); continue;} printf ("% C % d,", 'A' + (J + 1) /4--I/2) ;}} cout <"Black:"; for (k = 0; k <6; k ++) for (I = 1; I <= 17; I ++) for (j = 1; j <= 33; j ++) {if (I % 2 = 0 & J % 4 = 3 & K <= 4) if (map1 [I] [J] = white [k]) {printf ("% C % d,", black [K], 'A' + (J + 1)/4-1, 9-I/2 );} if (k = 5 & I % 2 = 0 & J % 4 = 3) if (map1 [I] [J] = 'P ') {S2 --; If (s2 = 0) {printf ("% C % d \ n", 'A' + (J + 1) /4-1, 9-I/2); continue;} printf ("% C % d,", 'A' + (J + 1) /4--I/2);} return 0 ;}

The simulation questions such as basic slag can only be heap by time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.