C - 翻翻棋 FZU - 2230

象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将。根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃掉对方的棋子。将和帅为同一级别。然而胜负在只剩下帅和将的时候已定。

Input

第一行T,表示T组数据。

每组数据共有四行字符串,每行字符串共八个字符

’#’表示空格

’*’表示红方帅

’.’表示黑方将

此时红方先走

每组输入之间没有空行。

Output

每组数据输出一行。若为红方赢输出Red win,否则输出 Black win

Sample Input

1
######.#
#####*##
########
########

Sample Output

Black win

解题思路:由于红方先走,红方先走一步后,若两者之间的距离为偶数步,则黑方会赢,也就是说两者之间的距离为奇数步,则黑方赢,否则红方赢。 

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int i,j,tx,ty,sx,sy;
        char s[21][28];
        for(i=0; i<4; i++)
        {
            scanf("%s",s[i]);
            for(j=0; j<8; j++)
            {
                if(s[i][j]=='.')
                {
                    tx=i;
                    ty=j;
                }
                else if(s[i][j]=='*')
                {
                    sx=i;
                    sy=j;
                }
            }
        }
        if((abs(tx-sx)+abs(ty-sy))&1)
            cout<<"Red win"<<endl;
        else cout<<"Black win"<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41374539/article/details/82025236