• codeforces 519A. A and B and Chess,


    A. A and B and Chess
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A and B are preparing themselves for programming contests.

    To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.

    For each chess piece we know its weight:

    • the queen's weight is 9,
    • the rook's weight is 5,
    • the bishop's weight is 3,
    • the knight's weight is 3,
    • the pawn's weight is 1,
    • the king's weight isn't considered in evaluating position.

    The player's weight equals to the sum of weights of all his pieces on the board.

    As A doesn't like counting, he asked you to help him determine which player has the larger position weight.

    Input

    The input contains eight lines, eight characters each — the board's description.

    The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.

    The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'.

    The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively.

    An empty square of the board is marked as '.' (a dot).

    It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.

    Output

    Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.

    Sample test(s)
    input
    ...QK...
    ........
    ........
    ........
    ........
    ........
    ........
    ...rk...
    output
    White
    input
    rnbqkbnr
    pppppppp
    ........
    ........
    ........
    ........
    PPPPPPPP
    RNBQKBNR
    output
    Draw
    input
    rppppppr
    ...k....
    ........
    ........
    ........
    ........
    K...Q...
    ........
    output
    Black
    Note

    In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.

    In the second test sample the weights of the positions of the black and the white pieces are equal to 39.

    In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.

    一个简单的计数比较,坑点在于 the knight — as 'N'.

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<iomanip>
     5 #include<cctype>
     6 #include<string>
     7 #include<cmath>
     8 #include<cstdio>
     9 #include<cstdlib>
    10 #define LL long long
    11 #define PF(x) ((x)*(x))
    12 #define LF(x) ((x)*PF(x))
    13 
    14 using namespace std;
    15 const int INF=1<<31-1;
    16 const int max9=1e9;
    17 const int max6=1e6;
    18 const int max3=1e3;
    19 
    20 int gcd(int a,int b)
    21 {
    22     return b==0?a:gcd(b,a%b);
    23 }
    24 char str[100][100];
    25 int main()
    26 {
    27     int a,b;
    28     while(cin >> str[0])
    29     {
    30         int a=0;
    31         int b=0;
    32         for(int i=1;i<8;i++)
    33             cin >> str[i];
    34         for(int i=0;i<8;i++)
    35             for(int j=0;j<8;j++)
    36         {
    37             if(str[i][j]=='Q') a+=9;
    38             if(str[i][j]=='q') b+=9;
    39             if(str[i][j]=='R') a+=5;
    40             if(str[i][j]=='r') b+=5;
    41             if(str[i][j]=='B') a+=3;
    42             if(str[i][j]=='b') b+=3;
    43             if(str[i][j]=='N') a+=3;
    44             if(str[i][j]=='n') b+=3;
    45             if(str[i][j]=='P') a+=1;
    46             if(str[i][j]=='p') b+=1;
    47 
    48         }
    49         if(a>b) cout << "White" << endl;
    50         else if(a==b) cout << "Draw" << endl;
    51         else cout << "Black" << endl;
    52     }
    53     return 0;
    54 }
    View Code
  • 相关阅读:
    bcftools 为 vcf 文件建索引及合并 vcf 文件
    Linux 替换^M字符方法
    shell 字符串分割方法简介
    shell 数组介绍及相关操作
    Annovar 信息注释
    C++ string与数值的转换
    C/C++ 删除文件 remove函数
    关于内核转储(core dump)的设置方法
    mac下nginx安装
    linux独有的sendfile系统调用--“零拷贝,高效”
  • 原文地址:https://www.cnblogs.com/I-love-HLD/p/4306578.html
Copyright © 2020-2023  润新知