#P2113. ACSL 2024-2025 Intermediate Division Contest #2 Uno Duo

ACSL 2024-2025 Intermediate Division Contest #2 Uno Duo

PROBLEM DESCRIPTION

The card game Duo uses cards that have 33 characteristics: a color, number, and symbol. The game starts with two face-up cards and 77 cards in the player’s hand. On a single turn, the player can choose one of the two face-up cards and match as many cards from their hand as possible on that pile. A card can be placed on top of another card if exactly 22 of the characteristics match.

The ACSL cards use four colors (R = red, Y = yellow, G = green, B = blue), four numbers (1, 2, 3, 4), and four symbols (X = cross, O = circle, S = square, T = triangle). A card is represented by a 33-character string showing the color, number, and symbol, in that order. For example, the card R4S, shown on the left, is red with the number 4 and contains a square. There are 99 cards that could possibly be placed on top of this card: a red square with the number 1, 2, or 3; a yellow, green, or blue square with the number 4; a red cross, circle, or triangle with the number 4.

In this version of the game called Uno Duo, your program will play one turn for a single player. The turn begins with two face-up cards and 77 cards in the hand (think of them as being held from left to right). For each pile, perform the following steps during a single turn:

  1. Find the leftmost card in your hand that matches the face-up card on that pile. Place the matched card on the top, thus creating a face-up pile of cards.
  2. Try to match as many cards in your hand on that pile. Each time, look at your cards starting at the leftmost. If the card is a match, place it on top of that pile of cards.
  3. Stop when you cannot play any more cards in your hand.

You must choose the pile in which you can play the most number of cards. The output is a string containing all of the cards in the pile where the most number of cards were placed, from bottom to top, each separated by a single space. If there is a tie, output Pile #1.

INPUT FORMAT

There will be two strings. The first string is the two face-up cards. The second string is the 77 cards in the player’s hand. All cards are separated by a single space. There will be no duplicate cards in each data set.

OUTPUT FORMAT

Output a string containing all of the cards in the pile where the most cards can be placed, from bottom to top. Separate the cards by a single space.

SAMPLE

INPUT #1

R4S B3O
R3X B1T B2T R1X B3X B1X Y4O

OUTPUT #1

B3O B3X R3X R1X B1X B1T B2T

INPUT #2

R4S B3O
R4X B4X B3X B3T G3T G1T R1O

OUTPUT #2

R4S R4X B4X B3X B3T G3T G1T

INPUT #3

B1T B2T
G1O B1O R1T B4T G4O R4O R1X

OUTPUT #3

B1T B1O G1O G4O R4O

INPUT #4

G3S Y4T
R3S G1O B4X G2S Y4S G3T G3X

OUTPUT #4

G3S R3S

INPUT #5

B1S Y4O
B4O Y3O R4X B2X G2X Y3T R3S

OUTPUT #5

Y4O B4O

INPUT #6

G2T G3X
Y1S G4S B4S G2S R1T G2X Y2T

OUTPUT #6

G3X G2X G2S G4S B4S

EXPLANATION

Sample #1 Explanation

Initially, the two face-up cards and the 77 cards in the hand are as follows:

The illustrations show the cards that can be placed on Pile #2. The first card that matches B3O is B3X so it is transferred to the face-up pile.

The remaining moves are as follows:

At this point, the only card remaining in the hand is Y4O. It cannot be placed on the pile, so the cards that can be placed on Pile #2, including the face-up card, are: B3O B3X R3X R1X B1X B1T B2T. There are no cards that can be placed on pile #1. However, were pile #1 to be R4X, then cards R3X R1X B1X B1T B2T could be placed on it.