
ZOJ Problem Set  3043
Gongzhu
Time Limit: 2 Seconds
Memory Limit: 65536 KB
Gongzhu is a very popular card game played by 4 players in China, players get some points after a game, and the one with the highest points wins.
Given the cards the players give out every round, you are asked to write a program to tell how many points the 4 players get after the game.
Here are the rules for the game:
 Cards needed: a standard deck of 52 cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K of Clubs, Diamonds, Hearts and Spades).
 The order of the cards (from greatest to least): A K Q J 10 9 8 7 6 5 4 3 2 for each suit.
 Special card
 "Pig": Spade Q
 "Sheep": Diamond J
 "Change": Club 10
 Cards with points: "Pig", "Sheep", "Change" and all the Hearts.
 100 points for "Pig"
 100 points for "Sheep"
 0 points for Heart 2, 3, 4 (they are different from the cards without points, although they are 0 point)
 10 points for Heart 5, 6, 7, 8, 9, 10
 20 points for Heart J
 30 points for Heart Q
 40 points for Heart K
 50 points for Heart A
 If one gets "Change" and does not have any other cards with points (the cards above), then he gets 50 points; Otherwise, he gets 2*[the total point of all the other cards with points he has].
 How to give out the card
In real Gongzhu game, players must follow suit. But here we make it easier: you can give out one card of any suit in each round. In each round, the one gives out the greatest card gets all the cards with points in this round, and will be the first one to give out a card in the next round. The cards of same suit are ordered as rule 2, and for different suits, the one gives out the card earlier is greater.
 Full_Red
If a player gets all the Hearts in a game, then these 13 cards turn to 200 points.
 Full_All
If a player gets all the cards with points (13 Hearts and the three special cards) in a game, then he gets 800 points.
Input
First, an integer N, the number of cases.
For each case:
 Four strings: the names of the 4 players.
 The name of the player who gives out the card in the first round. After that, the one gives out the greatest card leads the next round. For example: 4 players A, B, C and D, B is the first one to give out the card in the first round, the order they give out the cards in the first round will be B C D A, assume in this round, C gives out the greatest card, then the order in the next round will be C D A B.
 An integer M (1 <= M <= 13) which is the number of rounds have been played.
 M lines, each line shows the 4 cards given out in the round, ordered by the time when they're given out.
The cards are represented like this:
Suit Value
Suit will be one of Club, Diamond, Heart and Spade.
Value will be one of A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K.
Output
4 lines for each case, each line is:
Name Score (the total points of the M rounds)
The order of the names is the same as the input.
Output a blank line between cases.
Sample Input
1
A B C D
A
2
Club A Club 10 Club 9 Heart A
Club Q Club K Heart K Heart Q
Sample Output
A 100
B 70
C 0
D 0
Author: CHAO, Jiansong
Source: ZOJ Monthly, September 2008
Submit
Status
