下棋

C - PawnChess

Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».

This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed.

 

Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (r, c) the cell located at the row r and at the column c.

There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner.

Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players.

Moving upward means that the pawn located in (r, c) will go to the cell (r - 1, c), while moving down means the pawn located in (r, c) will go to the cell (r + 1, c). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color.

Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available.

Input

The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.

It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row.

Output

Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.

Example

Input

........
........
.B....B.
....W...
........
..W.....
........
........

Output

A

Input

..B.....
..W.....
......B.
........
.....W..
......B.
........
........

Output

B

Note

In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.

 

 

#include<stdio.h>

int main(void)

{

    int i,j,k;

    char a[10][10];

    for(i=0;i<8;i++)

        scanf("%s",a[i]);

    int t1=10,t2=10;

    for(i=0;i<8;i++)

    {

        for(j=0;j<8;j++)

        {

            if(a[i][j]=='W')

            {

                for(k=i-1;k>=0&&a[k][j]=='.';k--);

                if(k<0)

                {

                    if(t1>i)

                        t1=i;

                }

            }

            else if(a[i][j]=='B')

            {

                for(k=i+1;k<8&&a[k][j]=='.';k++);

                if(k>7)

                {

                    if(7-i<t2)

                    {

                        t2=7-i;

                    }

                }

            }

        }

    }

    if(t1<=t2)

        printf("A\n");

    else printf("B\n");

    return 0;

}

 

 

题目大意:

有一个 8*8 的矩阵(棋盘),有 B W ,B表示黑棋,W表示白棋,然后又两个人ABA拿白棋先走,

A想走到第一行,B想走到第八行,看谁先到达。。。

 

解题思路:

就是比较一下大小,需要注意的是如果BW在同一列,而且BW上面就直接跳过。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值