HDU 4461 The Power of Xiangqi

The Power of Xiangqi

Xiangqi is one of the most popular two-player board games in China. The game represents a battle between two armies with the goal of capturing the enemy’s “general” piece.
Now we introduce some basic rules of Xiangqi. Xiangqi is played on a 10×9 board and the pieces are placed on the intersections (points). There are two groups of pieces marked by black or red Chinese characters, belonging to the two players separately. During the game, each player in turn moves one piece from the point it occupies to another point. No two pieces can occupy the same point at the same time. A piece can be moved onto a point occupied by an enemy piece, in which case the enemy piece is “captured” and removed from the board. When the general is in danger of being captured by the enemy player on the enemy player’s next move, the enemy player is said to have “delivered a check”. If the general’s player can make no move to prevent the general’s capture by next enemy move, the situation is called “checkmate”.
Each player has 7 kinds of pieces in this game. Their names, offense power and symbol letters are shown in the table below:
HDU 4461 The Power of Xiangqi_第1张图片

Now show you the pieces of red player and black player, you are going to find out which player has the larger total offense power. Since Ma and Pao working together can have good effect, if a player has no Ma or no Pao, or has neither, his total offense power will be decreased by one. But the total offense power can’t be decreased to zero, it is at least one.

Input

The first line is an integer T ( T <= 20) meaning there are T test cases.
For each test case: The first line shows which pieces the red player has. It begins with an integer n ( 0 < n <= 16) meaning the number of pieces.
Then n letters follows, all separated by one or more blanks. Each letter is a symbol letter standing for a piece, as shown in the table above.
The second line describes the situation of the black player, in the same format as the first line.

Output

For each test case, if the red player has more offense power, then print “red”. If the black player has more offense power, then print “black”. If there is a tie, print “tie”.

Sample Input

3
2 A B
2 A B
7 A A B C D D F
7 A A B B C C F
5 A A B B F
3 A B F

Sample Output

tie
black
red


题目比较简单,累加求和比较大小,唯一需要注意的是如果没有A或者没有B,或者两个都没有,则总数要减去1

AC

#include 
#include 
#include 
using namespace std;

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        char x,y;
        int r,b;
        int sum_red=0;
        int sum_black=0;
        int flagb=0,flagc=0;
        cin>>r;
        for(int i=0; icin>>x;
            if(x=='A')
                sum_red+=16;
            else if(x=='B')
            {
                sum_red+=7;
                flagb++;
            }
            else if(x=='C')
            {
                sum_red+=8;
                flagc++;
            }
            else if(x=='D')
                sum_red+=1;
            else if(x=='E')
                sum_red+=1;
            else if(x=='F')
                sum_red+=2;
            else if(x=='G')
                sum_red+=3;
        }
        if(flagb==0||flagc==0&&sum_red>1)
            sum_red-=1;
        flagb=0;
        flagc=0;
        getchar();
        cin>>b;
        for(int i=0; icin>>y;
            if(y=='A')
                sum_black+=16;
            else if(y=='B')
            {
                sum_black+=7;
                flagb++;
            }
            else if(y=='C')
            {
                sum_black+=8;
                flagc++;
            }
            else if(y=='D')
                sum_black+=1;
            else if(y=='E')
                sum_black+=1;
            else if(y=='F')
                sum_black+=2;
            else if(y=='G')
                sum_black+=3;
        }
        if(flagb==0||flagc==0&&sum_black>1)
            sum_black-=1;
        if(sum_red==sum_black)
            cout<<"tie"<else if(sum_red>sum_black)
            cout<<"red"<else if(sum_redcout<<"black"<return 0;
}

你可能感兴趣的:(HDU)