Undercut
InterviewTime limit1sMemory limit128 MB
Score a five-round card game where players reveal numbered cards each round, applying undercut and tie rules, and print both totals.
- Level
Easy3 of 10
- Topics
- Implementation, Simulation, Brute force, Math
- Solved
- No attempts yet
Problem
Undercut is a card game for two players. Each player holds five cards numbered 1 through 5. In every round both players secretly choose one of their cards and then reveal it at the same time. That round is scored as follows:
- If the two cards have equal value, no one scores.
- If the two cards differ by more than one point, the player who revealed the larger card scores points equal to the value of that larger card.
- If the two cards differ by exactly one point (an undercut), the player who revealed the smaller card scores the sum of the two cards. The single exception is when the cards are 1 and 2: the player with the smaller card scores 6 points instead of 3.
After each round every card returns to its owner's hand, and the next round is played with the full set of five cards again.
For example, over 5 rounds player A plays 5, 3, 1, 3, 5 and player B plays 3, 3, 3, 3, 4. Round by round: A scores 5, then no score, then B scores 3, then no score, then B scores 9. The totals are A: 5 and B: 12.
Given the cards played by both players, determine their final scores.
Input
The input contains several games. Each game is described on three lines. The first line holds an integer (); a value of ends the input and is not part of any game. The next two lines each contain integers between 1 and 5 inclusive: the first of these lines lists player A's cards for the rounds, and the second lists player B's cards for the same rounds.
Output
For each game, print one line in the form:
A has a points. B has b points.
where and are the final scores of player A and player B. Separate consecutive output lines with a blank line.