A and B and Chess 519A

来源:互联网 发布:windows 安全 编辑:程序博客网 时间:2024/05/17 01:12

python 版答案

原问题:

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.


AC的答案:

W = 0B = 0for i in range(0,8):    a = input()    for j in a:        if j == 'Q':            W = W + 9         elif j == 'R':            W = W + 5         elif j == 'B':            W = W + 3        elif j == 'N':            W = W + 3        elif j == 'P':            W = W + 1        elif j == 'q':            B = B + 9        elif j == 'r':            B = B + 5        elif j == 'b':            B = B + 3        elif j == 'n':            B = B + 3        elif j == 'p':            B = B + 1 if B>W:    print('Black')elif B<W:    print('White')else:    print('Draw')


  

   



原创粉丝点击