POJ 2993-emag eht htiw Em Pleh (simulation-to restore the chessboard based on the pawn position)

Source: Internet
Author: User
Tags cas printf strcmp strlen
Emag eht htiw Em Pleh
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3492 Accepted: 2294

Description This problem was a reverse case of the problem 2996. You are given the output of the problem H and your task was 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 CTU Open 2005
The title means: contrary to the POJ 2996 (http://blog.csdn.net/mikasa3/article/details/54630409), the position of the given pawn, the output of the restored chessboard.
problem-Solving ideas: simulation problems, white black chess to engage in one, note that the scope of the array can not be opened small. This question I originally used the C + + input and output, has been abnormally interrupted, the error prompt is as follows:

GLIBC detected * * *./prog:free (): Invalid pointer:0x08fc0028 * * *
======= backtrace: =========
/lib/libc.so. 6[0X557F41F5]
/lib/libc.so.6 (cfree+0x9c) [0X557F5ACC]
/usr/lib/libstdc++.so.6 (_zdlpv+0x21) [0X5571F2E1]
/usr/lib/libstdc++.so.6 (_ZNSS4_REP10_M_DESTROYERKSAICE+0X1D) [0x556fbb2d]
/usr/lib/libstdc++.so.6 (_ ZNSS7RESERVEEJ+0XAD) [0x556fd73d]
/usr/lib/libstdc++.so.6 (_znss6appendepkcj+0x8d) [0x556fd93d]
/usr/lib/ Libstdc++.so.6 (_zstrsicst11char_traitsicesaiceerst13basic_istreamit_t0_es7_rsbis4_s5_t1_e+0x169) [0x556d6a89]
./prog (__gxx_personality_v0+0x453) [0X8048DBB]
./prog (__gxx_personality_v0+0x79) [0x80489e1]
===== = = Memory Map: ========

Looked for a long time do not know where wrong, then changed to C input and output, operating normal, AC.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <

Algorithm> #include <cmath> using namespace std;
    int col (char c)//Output column {if (c== ' a ') return 2;
    else if (c== ' B ') return 6;
    else if (c== ' C ') return 10;
    else if (c== ' d ') return 14;
    else if (c== ' E ') return 18;
    else if (c== ' F ') return 22;
    else if (c== ' G ') return 26;
    else if (c== ' h ') return 30;
return 0;
    } int row (char c)//output line {if (c== ' 1 ') return 15;
    else if (c== ' 2 ') return 13;
    else if (c== ' 3 ') return 11;
    else if (c== ' 4 ') return 9;
    else if (c== ' 5 ') return 7;
    else if (c== ' 6 ') return 5;
    else if (c== ' 7 ') return 3;
    else if (c== ' 8 ') return 1;
return 0;
} Char ma[18][34];
                     void Init ()//will border and. And: INSERT into the appropriate location {char frame[34]= {' + ', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-',
    '+','-','-','-','+','-','-','-','+','-','-','-','+','-','-','-','+'
                    };
 for (int i=0; i<17; i+=2)       for (int j=0; j<33; j + +) Ma[i][j]=frame[j];
    for (int i=1, i<17; i+=2) for (int j=0; j<33; j+=4) ma[i][j]= ' | ';
    int t;
            for (int i=1, i<17; i+=4) for (int. j=1; j<33; j+=8) {for (int k=0; k<3; ++k)
                {t=j;
            Ma[i][j+k]= '. ';
        } j=t;
            } for (int i=3, i<17; i+=4) for (int. j=1; j<33; j+=8) {for (int k=0; k<3; ++k)
                {t=j;
            ma[i][j+k]= ': ';
        } j=t;
            } for (int i=1, i<17; i+=4) for (int. j=5; j<33; j+=8) {for (int k=0; k<3; ++k)
                {t=j;
            ma[i][j+k]= ': ';
        } j=t;
            } for (int i=3, i<17; i+=4) for (int. j=5; j<33; j+=8) {for (int k=0; k<3; ++k)
       {t=j;         Ma[i][j+k]= '. ';
        } j=t; }} void output ()//output Checkerboard {for (Int. i=0; i<17; i++) {for (int j=0; j<33; j + +) printf ("%c",
        MA[I][J]);
    printf ("\ n");
    }} int main () {Init ();
    int cas=2;
Char color[10];
    #ifdef Online_judge #else freopen ("F:/cb/read.txt", "R", stdin);
Freopen ("F:/cb/out.txt", "w", stdout);
        #endif while (cas--) {scanf ("%s", color);
            if (!strcmp (color, "white:"))//The result of the comparison is 0, the match succeeds {char str[50];
            scanf ("%s", str);
            Char s[3];
            int cnt=0;
                    for (int i=0; I<strlen (str); ++i) {if (str[i]== ', ')//comma-separated points for each position {
                    if (s[0]>= ' A ' &&s[0]<= ' Z ') Ma[row (s[2])][col (s[1])]=s[0];
                    else if (s[0]>= ' a ' &&s[0]<= ' Z ') Ma[row (s[1])][col (s[0])]= ' P '; Cnt=0;
            } else s[cnt++]=str[i]; } if (s[0]>= ' a ' &&s[0]<= ' z ')//Note that the last position is followed by a comma-free, so to handle Ma[row (S[1])][col (s[0])]= ' P
        ';
            } else if (!strcmp (color, "Black:")) {char str[70];
            scanf ("%s", str);
            Char s[3];
            memset (S, ' n ', sizeof (s));
            int cnt=0,pos; for (int i=0; I<strlen (str); ++i) {if (str[i]== ', ') {if
                    (s[0]>= ' A ' &&s[0]<= ' Z ') Ma[row (s[2])][col (s[1])]=tolower (s[0]);
                    else if (s[0]>= ' a ' &&s[0]<= ' Z ') Ma[row (s[1])][col (s[0])]= ' P ';
                    cnt=0;
                memset (S, ' n ', sizeof (s));
            } else s[cnt++]=str[i];
        } if (s[0]>= ' a ' &&s[0]<= ' Z ') Ma[row (s[1])][col (s[0])]= ' P ';}} output ();
return 0; }/* 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 * *


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.