zoukankan      html  css  js  c++  java
  • POJ 2996 Help Me with the Game

    Help Me with the Game
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 3292   Accepted: 2122

    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,h6

    脑残模拟!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    !!!

    。。!!!。。!

    。!

    。。!

    !。!!

    AC代码例如以下:


    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main()
    {
        char map[50][50];
        int Ph[20],ph[20];
        int Rt,rt,Bt,bt,Nt,nt,Pt,pt,Kt,kt,Qt,qt;
        int Rh[20],rh[20],Bh[20],bh[20],Nh[20],nh[20];
        char Rz[20],rz[20],Bz[20],bz[20],Nz[20],nz[20],Pz[20],pz[20];
        int Kh,kh,Qh,qh;
        char Kz,kz,Qz,qz;
        int i,j;
        for(i=0;i<17;i++)
            cin>>map[i];
        Rt=rt=Bt=bt=Nt=nt=Pt=pt=Kt=kt=Qt=qt=0;
        for(i=1;i<17;i+=2)
        {
            for(j=2;j<33;j+=4)
            {
                if(map[i][j]=='k')
                {kh=8-i/2;kz=(char)j/4+'a';kt++;}
                if(map[i][j]=='q')
                {qh=8-i/2;qz=(char)j/4+'a';qt++;}
                if(map[i][j]=='r')
                {rh[rt]=8-i/2;rz[rt]=(char)j/4+'a';rt++;}
                if(map[i][j]=='b')
                {bh[bt]=8-i/2;bz[bt]=(char)j/4+'a';bt++;}
                if(map[i][j]=='n')
                {nh[nt]=8-i/2;nz[nt]=(char)j/4+'a';nt++;}
                if(map[i][j]=='p')
                {ph[pt]=8-i/2;pz[pt]=(char)j/4+'a';pt++;}
            }
        }
        for(i=15;i>=1;i-=2)
        {
            for(j=2;j<33;j+=4)
            {
                if(map[i][j]=='K')
                {Kh=8-i/2;Kz=(char)j/4+'a';Kt++;}
                if(map[i][j]=='Q')
                {Qh=8-i/2;Qz=(char)j/4+'a';Qt++;}
                if(map[i][j]=='R')
                {Rh[Rt]=8-i/2;Rz[Rt]=(char)j/4+'a';Rt++;}
                if(map[i][j]=='B')
                {Bh[Bt]=8-i/2;Bz[Bt]=(char)j/4+'a';Bt++;}
                if(map[i][j]=='N')
                {Nh[Nt]=8-i/2;Nz[Nt]=(char)j/4+'a';Nt++;}
                if(map[i][j]=='P')
                {Ph[Pt]=8-i/2;Pz[Pt]=(char)j/4+'a';Pt++;}
            }
        }
        cout<<"White: ";
        if(Kt!=0)
        cout<<"K"<<Kz<<Kh<<",";
        if(Qt!=0)
        cout<<"Q"<<Qz<<Qh<<",";
        for(i=0;i<Rt;i++)
            cout<<"R"<<Rz[i]<<Rh[i]<<",";
        for(i=0;i<Bt;i++)
            cout<<"B"<<Bz[i]<<Bh[i]<<",";
        for(i=0;i<Nt;i++)
            cout<<"N"<<Nz[i]<<Nh[i]<<",";
        for(i=0;i<Pt;i++)
            if(i!=Pt-1)
            cout<<Pz[i]<<Ph[i]<<",";
        else cout<<Pz[i]<<Ph[i]<<endl;
        cout<<"Black: ";
        if(kt!=0)
        cout<<"K"<<kz<<kh<<",";
        if(qt!=0)
        cout<<"Q"<<qz<<qh<<",";
        for(i=0;i<rt;i++)
            cout<<"R"<<rz[i]<<rh[i]<<",";
        for(i=0;i<bt;i++)
            cout<<"B"<<bz[i]<<bh[i]<<",";
        for(i=0;i<nt;i++)
            cout<<"N"<<nz[i]<<nh[i]<<",";
        for(i=0;i<pt;i++)
            if(i!=pt-1)
            cout<<pz[i]<<ph[i]<<",";
        else cout<<pz[i]<<ph[i]<<endl;
        return 0;
    }
    



  • 相关阅读:
    任务18格式化
    任务17分区
    任务16 BIOS与CMOS
    任务15硬件组装过程说明
    任务14选配机箱
    任务13选配电源
    任务12选配显卡
    任务11选配机械硬盘
    任务10选配固态硬盘
    Android自定义控件:动画类(八)----ObjectAnimator基本使用
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5362579.html
Copyright © 2011-2022 走看看