#P1148. 拱猪计分

拱猪计分

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 S,H,D,C\texttt S, \texttt H, \texttt D, \texttt C to represent Spades, Hearts, Diamonds, and Clubs, and numbers 11 to 1313 to represent ranks A,2,,Q,K\texttt A, \texttt 2, \dots, \texttt Q, \texttt K. For example, H1H_1 is Heart A\texttt A, and S13S_{13} is Spade K\texttt K.
  2. At the end of the deal, the only cards that matter for scoring (scoring cards) are the “Pig” S12S_{12}, all Heart cards, the “Sheep” D11D_{11}, and the “Double” C10C_{10} — a total of 1616 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 1616 cards, their score is 00.
  3. If the player who holds C10C_{10} has that card and no other scoring cards, they score +50+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 1313 Heart cards H1H_1 to H13H_{13} are negative, with values $-50, -2, -3, -4, -5, -6, -7, -8, -9, -10, -20, -30, -40$ in order. Also, S12S_{12} and D11D_{11} are scored as 100-100 and +100+100 points, respectively.
  5. If the Heart cards H1H_1 to H13H_{13} are all held by a single player, then:
  • All Heart cards are scored as +200+200 points. This means the set of all Heart cards is worth +200+200 in total, not +200+200 per card.
  • If S12S_{12} and D11D_{11} are both also held by the same player who took all the Hearts, that player scores +500+500 points. This +500+500 does not stack with the +200+200 from the Hearts. Otherwise, these two cards are scored according to the earlier rules.
  • The C10C_{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-148, +83, -138, and 60-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+200, -200, +100, and 00.

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 00, 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 44 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.

4  S12  H3  H5  H13
3  D11  H8  H9
6  C10  H1  H2  H4  H6  H7
3  H10  H11 H12
13 H1  H2  H3  H4  H5  H6  H7  H8  H9  H10  H11  H12  H13  
2  S12  C10
1  D11
0
0
0
0
0

-148 +83 -138 -60
+200 -200 +100 0

Hint

The two sample test cases correspond to the examples in the statement.

Translated by ChatGPT 5