P1148 Gongzhu Scoring
Description
“Gongzhu” is a very interesting card game. Even if you do not know how to play it, you can appreciate its fun from the scoring rules. Here we only consider a four-player Gongzhu deal. Based on the rules below, compute the final score of each player when the deal ends.
1. We use $\texttt S, \texttt H, \texttt D, \texttt C$ to represent Spades, Hearts, Diamonds, and Clubs, and numbers $1$ to $13$ to represent ranks $\texttt A, \texttt 2, \dots, \texttt Q, \texttt K$. For example, $H_1$ is Heart $\texttt A$, and $S_{13}$ is Spade $\texttt K$.
2. At the end of the deal, the only cards that matter for scoring (scoring cards) are the “Pig” $S_{12}$, all Heart cards, the “Sheep” $D_{11}$, and the “Double” $C_{10}$ — a total of $16$ cards. All other cards are discarded and do not count (that is, they are not considered in the scoring process below). If a player holds none of these $16$ cards, their score is $0$.
3. If the player who holds $C_{10}$ has that card and no other scoring cards, they score $+50$ points. Otherwise, double the sum of that player’s other scoring cards.
4. If the Heart cards are not all held by a single player, then the $13$ Heart cards $H_1$ to $H_{13}$ are negative, with values $-50, -2, -3, -4, -5, -6, -7, -8, -9, -10, -20, -30, -40$ in order. Also, $S_{12}$ and $D_{11}$ are scored as $-100$ and $+100$ points, respectively.
5. If the Heart cards $H_1$ to $H_{13}$ are all held by a single player, then:
- All Heart cards are scored as $+200$ points. This means the set of all Heart cards is worth $+200$ in total, not $+200$ per card.
- If $S_{12}$ and $D_{11}$ are both also held by the same player who took all the Hearts, that player scores $+500$ points. This $+500$ does not stack with the $+200$ from the Hearts. Otherwise, these two cards are scored according to the earlier rules.
- The $C_{10}$ card is still scored according to the earlier rules.
Example 1: If the players’ scoring cards are:
1. `S12 H3 H5 H13`
2. `D11 H8 H9`
3. `C10 H1 H2 H4 H6 H7`
4. `H10 H11 H12`
Then the scores for the four players, in order, are: $-148, +83, -138$, and $-60$.
Example 2: If the players’ scoring cards are:
1. `H1 H2 H3 H4 H5 H6 H7 H8 H9 H10 H11 H12 H13`
2. `S12 C10`
3. `D11`
4. None
Then the scores for the four players, in order, are: $+200, -200, +100$, and $0$.
Input Format
Each input file contains multiple test cases.
Each test case has four lines, one per player.
On each line, the first number is the total count of scoring cards held by that player, followed by that many strings describing all their scoring cards. The count and the cards are separated by one or more spaces.
There are no blank lines between consecutive test cases. If all four players’ counts are $0$, the input ends and this test case should not be processed.
Output Format
Each line corresponds to one test case’s result and contains the four players’ scores, in order, as $4$ integers with a sign if nonzero. Adjacent integers are separated by a single space.
There is no space between the sign and the number. Do not print blank lines between test cases.
Explanation/Hint
The two sample test cases correspond to the examples in the statement.
Translated by ChatGPT 5