CF A and B and Chess

本文介绍了一个简单的程序,用于计算并比较国际象棋中白方和黑方棋子的总权重,以此来判断哪一方的棋局更为有利。通过读取棋盘布局,程序将根据每种棋子的预设权重来计算总分,并输出结果。
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




水题。。。MAP第一发
 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <string>
 5 #include <algorithm>
 6 #include <cctype>
 7 #include <queue>
 8 #include <map>
 9 using    namespace    std;
10 
11 const    int    SIZE = 10;
12 char    MAP[SIZE][SIZE];
13 int    main(void)
14 {
15     map<char,int>    white;
16     map<char,int>    black;
17     white['Q'] = 9;
18     white['R'] = 5;
19     white['B'] = 3;
20     white['N'] = 3;
21     white['P'] = 1;
22     white['K'] = 0;
23 
24     black['q'] = 9;
25     black['r'] = 5;
26     black['b'] = 3;
27     black['n'] = 3;
28     black['p'] = 1;
29     white['k'] = 0;
30 
31     int    sum_w,sum_b;
32     char    ch;
33     sum_w = sum_b = 0;
34     for(int i = 0;i < 8;i ++)
35         for(int j = 0;j < 8;j ++)
36         {
37             scanf(" %c",&ch);
38             if(islower(ch))
39                 sum_b += black[ch];
40             else    if(isupper(ch))
41                 sum_w += white[ch];
42         }
43     if(sum_w > sum_b)
44         puts("White");
45     else    if(sum_w < sum_b)
46         puts("Black");
47     else
48         puts("Draw");
49 
50     return    0;
51 }

 

转载于:https://www.cnblogs.com/xz816111/p/4412346.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值