Super Nausea Simulated Question K-Emag eht htiw Em Pleh

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

Mysterious 2996 in the title: Put down the following:

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

Thought: 2996 is the reverse thinking, give the position, output chessboard.

Firstly, the position of white chess is given, and the position of black chess is given in the second line.
(Given in the order of "K" (King), "Q" (Queen), "R" (Rook), "B" (Bishop), "N" (Knight), or "P" (Pawn). But the letter P is not entered.
In fact, the input is ordered, but the question is not related to the order.
Just remember, the letters and numbers between commas represent: a to h, columns 1 to 8, columns 1 to 8, lines 8 to 1.

AC Code:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<math.h>
#Include < string >// Lost header file, local operation is okay, submission is okay.
using namespace std;

char I[10][10];
int main()
{
    for(int i=1;i<=8;i++)
        for(int j=1;j<=8;j++)
            I[i][j]=((i+j)%2==0)?'.':':';//Is it a colon or a full stop?
            
    string a;
    getline(cin,a);//Enter a line directly, so you can traverse it.
    
    for(int i=7;i<a.size();i++)//The white and black words in front occupy the top six coordinates. Direct access to OK
    {
        if(a[i]=='K')//Simple violence can be divided into six situations. It's easy to understand. Anyway, first write one, then CV5 times.
        {
            int y=a[i+1]-'a'+1;//Column coordinates
            int x=a[i+2]-'0';//Row coordinates
            x=9-x;//Row coordinates are inverse
            I[x][y]='K';
            i += 3;//Then traverse backwards
        }
        else if(a[i]=='Q')
        {
            int y=a[i+1]-'a'+1;
            int x=a[i+2]-'0';
            x=9-x;
            I[x][y]='Q';
            i += 3;
        }
        else if(a[i]=='R')
        {
            int y=a[i+1]-'a'+1;
            int x=a[i+2]-'0';
            x=9-x;
            I[x][y]='R';
            i += 3;
        }
        else if(a[i]=='B')
        {
            int y=a[i+1]-'a'+1;
            int x=a[i+2]-'0';
            x=9-x;
            I[x][y]='B';
            i += 3;
        }
        else if(a[i]=='N')
        {
            int y=a[i+1]-'a'+1;
            int x=a[i+2]-'0';
            x=9-x;
            I[x][y]='N';
            i += 3;
        }
        else
        {
            int y=a[i]-'a'+1;
            int x=a[i+1]-'0';
            x=9-x;
            I[x][y]='P';
            i += 2;//Note, when CV, don't + 3.
        }
    }
    //Change the top of CV to lowercase
    getline(cin,a);
    for(int i=7;i<a.size();i++)
    {
        if(a[i]=='K')
        {
            int y=a[i+1]-'a'+1;
            int x=a[i+2]-'0';
            x=9-x;
            I[x][y]='k';
            i += 3;
        }
        else if(a[i]=='Q')
        {
            int y=a[i+1]-'a'+1;
            int x=a[i+2]-'0';
            x=9-x;
            I[x][y]='q';
            i += 3;
        }
        else if(a[i]=='R')
        {
            int y=a[i+1]-'a'+1;
            int x=a[i+2]-'0';
            x=9-x;
            I[x][y]='r';
            i += 3;
        }
        else if(a[i]=='B')
        {
            int y=a[i+1]-'a'+1;
            int x=a[i+2]-'0';
            x=9-x;
            I[x][y]='b';
            i += 3;
        }
        else if(a[i]=='N')
        {
            int y=a[i+1]-'a'+1;
            int x=a[i+2]-'0';
            x=9-x;
            I[x][y]='n';
            i += 3;
        }
        else
        {
            int y=a[i]-'a'+1;
            int x=a[i+1]-'0';
            x=9-x;
            I[x][y]='p';
            i += 2;
        }
    }
    for(int i=1;i<=8;i++)//Output!!! Actually, it's a four-time cycle.
    {
        cout<<"+---+---+---+---+---+---+---+---+"<<endl;
        printf("|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|\n",I[i][1],I[i][2],I[i][3],I[i][4],I[i][5],I[i][6],I[i][7],I[i][8]);
        cout<<"+---+---+---+---+---+---+---+---+"<<endl;
        i++;
        printf("|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|:%c:|.%c.|\n",I[i][1],I[i][2],I[i][3],I[i][4],I[i][5],I[i][6],I[i][7],I[i][8]);
    }
    cout<<"+---+---+---+---+---+---+---+---+"<<endl;
    return 0;
}

Posted by fizzystutter on Mon, 08 Apr 2019 10:45:31 -0700