• Help Me with the Game


    Help Me with the Game

    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
      1 #include<cstdio>
      2 #include<cstring>
      3 #include<iostream>
      4 #include<cstdlib>
      5 using namespace std;
      6 struct node
      7 {
      8     int hang;
      9     int lie;
     10     int data;
     11     int jb;
     12 } white[33],black[33];
     13 int sw(char p)//只是为了让级别好记,好排序
     14 {
     15     if(p=='K' || p=='k') return 1;
     16     if(p=='Q' || p=='q') return 2;
     17     if(p=='R' || p=='r') return 3;
     18     if(p=='B' || p=='b') return 4;
     19     if(p=='N' || p=='n') return 5;
     20     if(p=='P' || p=='p') return 6;
     21     return 0;
     22 }
     23 int cmpw(const void*a,const void *b)//这个排序很是坑爹,最初一直没想这样写,结果还是这样,又快又方便
     24 {
     25     if(((node*)a)->jb!=((node*)b)->jb)
     26         return ((node*)a)->jb-((node*)b)->jb;
     27     if(((node*)a)->hang!=((node*)b)->hang)
     28         return ((node*)a)->hang-((node*)b)->hang;
     29     return ((node*)a)->lie-((node*)b)->lie;
     30 }
     31 int cmpb(const void*a,const void *b)
     32 {
     33     if(((node*)a)->jb!=((node*)b)->jb)
     34         return ((node*)a)->jb-((node*)b)->jb;
     35     if(((node*)a)->hang!=((node*)b)->hang)
     36         return ((node*)b)->hang-((node*)a)->hang;
     37     return ((node*)a)->lie-((node*)b)->lie;
     38 }
     39 int main()
     40 {
     41     int wi=0,bi=0,i;
     42     char ch;
     43     for(i=8; i>0; i--)
     44     {
     45         scanf("+---+---+---+---+---+---+---+---+
    ");
     46         int sum=0;
     47         while(scanf("%c",&ch)&&ch!='
    ')
     48         {
     49             if('A'<=ch&&ch<='Z')
     50             {
     51                 white[wi].hang=i;
     52                 white[wi].lie=sum;//明显第几列和“|”的数目挂钩
     53                 white[wi].data=ch;
     54                 white[wi].jb=sw(ch);
     55                 wi++;
     56             }
     57             else if('a'<=ch&&ch<='z')
     58             {
     59                 black[bi].hang=i;
     60                 black[bi].lie=sum;
     61                 black[bi].data=ch;
     62                 black[bi].jb=sw(ch);
     63                 bi++;
     64             }
     65             else if(ch=='|')//再剩余的字符就不用看了
     66                 sum++;
     67         }
     68     }
     69     scanf("+---+---+---+---+---+---+---+---+");
     70     qsort(white,wi,sizeof(node),cmpw);//排序,这个让我纠结了好久,郁闷
     71     qsort(black,bi,sizeof(node),cmpb);
     72     wi--;
     73     bi--;
     74     printf("White: ");//这种坑爹的输出,好吧……只是很长,不复杂
     75     for(i=0; i<wi; i++)
     76     {
     77         if(white[i].data!='P')
     78             printf("%c",white[i].data);
     79         printf("%c",white[i].lie+'a'-1);
     80         printf("%d,",white[i].hang);
     81 
     82     }
     83     if(white[i].data!='P')
     84         printf("%c",white[i].data);
     85     printf("%c",white[i].lie+'a'-1);
     86     printf("%d
    ",white[i].hang);
     87     printf("Black: ");
     88     for(i=0; i<bi; i++)
     89     {
     90         if(black[i].data!='p')
     91             printf("%c",black[i].data-32);
     92         printf("%c",black[i].lie+'a'-1);
     93         printf("%d,",black[i].hang);
     94     }
     95     if(black[i].data!='p')
     96         printf("%c",black[i].data-32);
     97     printf("%c",black[i].lie+'a'-1);
     98     printf("%d
    ",black[i].hang);
     99     return 0;
    100 }
    View Code
  • 相关阅读:
    什么时候用到存储过程
    Group By
    李航统计学习方法(第二版)(五):k 近邻算法简介
    数据可视化之powerBI基础(十三)熟练使用Power BI的日期切片器
    数据可视化之powerBI基础(十二)PowerBI导入Excel数据有哪几种方式?
    数据可视化之powerBI基础(十一)Power BI中的数据如何导出到Excel中?
    数据可视化之powerBI基础(十)快速度量值,帮你更快的进行数据分析
    数据可视化之powerBI基础(九)Power BI中的“新表”,你会用吗?
    数据可视化之powerBI基础(八)PowerBI的表格,你真的会用吗
    数据可视化之powerBI基础(七)一文带你熟悉PowerBI建模视图中的功能
  • 原文地址:https://www.cnblogs.com/kongkaikai/p/3240970.html
Copyright © 2020-2023  润新知