暴力枚举——Help Me with the Game

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3394   Accepted: 2172

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

Source

#include<cstdio>
#include<string.h>
using namespace std;
char str[100][100];
char s[100];
int main()
{
    int i,j;
    int first=1;
    for(i=0; i<8; i++)
    {
        scanf("%s",s);
        getchar();
        scanf("%s",s);
        for(j=0; j<8; j++)
            str[i][j]=s[j*4+2];
    }
    printf("White: ");
    for(i=7; i>=0; i--)
        for(j=0; j<8; j++)
        {
            if(str[i][j]==‘K‘)
            {
                if(first==1)
                {
                    printf("K%c%d",‘a‘+j,8-i);
                    first=0;
                }
                else printf(",K%c%d",‘a‘+j,8-i);
            }
        }
    for(i=7; i>=0; i--)
        for(j=0; j<8; j++)
        {
            if(str[i][j]==‘Q‘)
            {
                if(first==1)
                {
                    printf("Q%c%d",‘a‘+j,8-i);
                    first=0;
                }
                else printf(",Q%c%d",‘a‘+j,8-i);
            }
        }
    for(i=7; i>=0; i--)
        for(j=0; j<8; j++)
        {
            if(str[i][j]==‘R‘)
            {
                if(first==1)
                {
                    printf("R%c%d",‘a‘+j,8-i);
                    first=0;
                }
                else printf(",R%c%d",‘a‘+j,8-i);
            }
        }
    for(i=7; i>=0; i--)
        for(j=0; j<8; j++)
        {
            if(str[i][j]==‘B‘)
            {
                if(first==1)
                {
                    printf("B%c%d",‘a‘+j,8-i);
                    first=0;
                }
                else printf(",B%c%d",‘a‘+j,8-i);
            }
        }
    for(i=7; i>=0; i--)
        for(j=0; j<8; j++)
        {
            if(str[i][j]==‘N‘)
            {
                if(first==1)
                {
                    printf("N%c%d",‘a‘+j,8-i);
                    first=0;
                }
                else printf(",N%c%d",‘a‘+j,8-i);
            }
        }
    for(i=7; i>=0; i--)
        for(j=0; j<8; j++)
        {
            if(str[i][j]==‘P‘)
            {
                if(first==1)
                {
                    printf("%c%d",‘a‘+j,8-i);
                    first=0;
                }
                else printf(",%c%d",‘a‘+j,8-i);
            }
        }
    first=1;
    printf("\n");
    printf("Black: ");
    for(i=0; i<=7; i++)
        for(j=0; j<8; j++)
        {
          if(str[i][j]==‘k‘)
          {
              if(first==1)
              {
                  printf("K%c%d",‘a‘+j,8-i);
                  first=0;
              }
              else printf(",K%c%d",‘a‘+j,8-i);
          }
        }
     for(i=0; i<=7; i++)
        for(j=0; j<8; j++)
        {
          if(str[i][j]==‘q‘)
          {
              if(first==1)
              {
                  printf("Q%c%d",‘a‘+j,8-i);
                  first=0;
              }
              else printf(",Q%c%d",‘a‘+j,8-i);
          }
        }
     for(i=0; i<=7; i++)
        for(j=0; j<8; j++)
        {
          if(str[i][j]==‘r‘)
          {
              if(first==1)
              {
                  printf("R%c%d",‘a‘+j,8-i);
                  first=0;
              }
              else printf(",R%c%d",‘a‘+j,8-i);
          }
        }
      for(i=0; i<=7; i++)
        for(j=0; j<8; j++)
        {
          if(str[i][j]==‘b‘)
          {
              if(first==1)
              {
                  printf("B%c%d",‘a‘+j,8-i);
                  first=0;
              }
              else printf(",B%c%d",‘a‘+j,8-i);
          }
        }
     for(i=0; i<=7; i++)
        for(j=0; j<8; j++)
        {
          if(str[i][j]==‘n‘)
          {
              if(first==1)
              {
                  printf("N%c%d",‘a‘+j,8-i);
                  first=0;
              }
              else printf(",N%c%d",‘a‘+j,8-i);
          }
        }
     for(i=0; i<=7; i++)
        for(j=0; j<8; j++)
        {
          if(str[i][j]==‘p‘)
          {
              if(first==1)
              {
                  printf("%c%d",‘a‘+j,8-i);
                  first=0;
              }
              else printf(",%c%d",‘a‘+j,8-i);
          }
        }
    return 0;
}

暴力枚举——Help Me with the Game

时间: 2024-10-13 16:11:39

暴力枚举——Help Me with the Game的相关文章

hdu5616 暴力枚举

2017-08-25 20:08:54 writer:pprp 题目简述: ? HDU 5616? n个砝码,可以放在天平左右两侧或不放? m次询问,每次询问是否可以测出给定重量? 1 ≤ n ≤ 20? 1 ≤ m ≤ 100 这道题采用枚举的思路的话实现起来还是有点困难的, 要实现的功能是对每个砝码进行处理,加到左边, 加到右边,或者是不加 看了大神的代码,感觉很巧妙, 设置了两个标记数组 vis1[2005], vis2[2005] 一个vis1用来记录当前已经可以实现的重量 另一个vis

hdu4282A very hard mathematic problem 暴力枚举

//给出k //找x,y,z使得x^z+y^z+x*y*z = k //x,y,z都为正整数x<y,z>1问有多少种方法 //当z = 2时,可以看到左边是一个完全平方 //而当z>=3时,可以暴力枚举x,y //由于k<2^31所以x<2^(31/3)枚举复杂度可以过 #include<cstdio> #include<cstring> #include<iostream> #include<cmath> using name

hdu 5247 找连续数【暴力枚举】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5247 分析:这道题是2015百度之星初赛1的2题,当时没看这道题 是队友看的,比完以后也做了一下,思路大体都是一样的,就是 暴力枚举,因为k<=1000,那么我们可以每一点x为起点跑[x,x+999] 这段区间,把每得到一段连续的子区间[x,?],则num[len]++(len=size([x,?])); 这样就可以了,最后num数组里就是对应的答案 献上代码: #include<stdio.h&

HDU 4770 Lights Against Dudely 暴力枚举+dfs

又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ czy Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1360    Accepted Subm

ZOJ3818-Pretty Poem(暴力枚举)

题目链接 题意:求所给字符串是否符合ABABA或者ABABCAB的形式,如果可以的话输出Yes,不可以的话为No. 思路:暴力枚举A和B的长度,再用从长度减去3倍的AB长度,即为C的长度,看组合而成的字符串是否与给定的相等.在这里string中的substr函数是个好东西. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <a

uva10892(暴力枚举)

把n的所有因子求出来,总数不会太多,所以直接O(n2)的暴力枚举所有对行不行. 有几个细节要注意,详见代码. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<map> #include<set> #include<vector> #include<algorit

暴力枚举 + 24点 --- hnu : Cracking the Safe

Cracking the Safe Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users: 46, Accepted users: 12 Problem 12886 : No special judgement Problem description Secret agent Roger is trying to crack a safe containing evil Syr

HNU 12886 Cracking the Safe(暴力枚举)

题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数,要你判断用 + .- . * ./.四种运算能不能得到一个结果为24的式子,可以用括号. 解释一下测试的第四组样例:应该是6 / (1 - 3 / 4) 暴力枚举三种符号分别是什么,然后枚举这三种符号运算的顺序,然后枚举这四个数字的24种排列方式,时间是4^3 * 6 * 24 然后注意要用double型,

HDU 4930 Fighting the Landlords(暴力枚举+模拟)

HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型,如果先手能一步走完,或者一步让后手无法管上,就赢 思路:先枚举出两个人所有可能的牌型的最大值,然后再去判断即可 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct Player { int rank[15]; } p1, p2; int t, h

区间Dp 暴力枚举+动态规划 Hdu1081

F - 最大子矩形 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Status Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*1 or greater located withi