Problem 109: Choker
(U.M. ACM Runoffs 2002, problem 2)
Description
Chickens, being greedy creatures,
play cards with 56-card decks. As usual, there are four suits: Spades,
Giblets, Diamonds, and Chickens, and within each suit the fourteen
cards range from the One (low) to the Chicken (high) in more-or-less
the traditional manner:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
Jack, Queen, King, Chicken.
For convenience, cards are
represented by a two character abbreviation consisting of a character
for the rank of the card, 1-9 and T=10, J=Jack, Q=Queen, K=King, C=Chicken,
followed by a character for the suit, S=Spades, G=Giblets, D=Diamonds,
C=Chickens. So for example, 3S represents the Three of Spades, TC is
the Ten of Chickens, CC is the Chicken of Chickens, and 1G is the One
of Giblets.
In Choker, a popular gambling
game, each player contributes an ante of twelve shillings into the pot,
and is dealt a hand of five cards. They then compare the hands, and the
player whose hand contains the winning combination of cards is the winner.
The winner receives all the money in the pot, and is strangled (hence the
name of the game) and baked into a pie.
The possible winning combinations
of cards are listed below, in descending order of winningness. For example,
a hand that contains three of a kind will always beat any hand that only has
two pairs. The order in which cards are received does not matter (e.g. if a
player receives first 6S then 3C then 6D then 9G and finally 3D, that is
still two pairs).
If two players are tied, there is
no winner. Note that these are not exactly the same as the rules of People
Choker (often abbreviated to Poker), in which ties are almost impossible,
and pies are not made.
Chickens are allowed to play with
themselves, but when they do, nobody wins.
- King of Kings: Any hand that contains the Chicken of Chickens beats
all other hands.
- Royal Flush: The Ten, Jack, Queen, King, and Chicken of the same suit.
If the top two players both have royal flushes, there is no winner.
- Straight Flush: Any unbroken sequence all of the same suit (e.g.
3C-4C-5C-6C-7C, or 8D-9D-TD-JD-QD). If the top two players have a straight
flush, the highest card determines the winner.
- Four of a Kind: Four cards of the same rank (obviously of different suits)
and one odd card (e.g. QC-QS-QG-QD-4C). If the top two players have four of
a kind, the rank of the four identical cards determines the winner.
- Full House: Three cards of the same rank together with two cards of
the same rank (e.g. QC-QS-QG-4D-4C). If two players have a full house,
then the rank of the three identical cards determines the winner.
- Flush: All five cards of the same suit, ranks irrelevant (e.g.
1S-2S-3S-4S-9S). If two players have a flush, then the rank of the highest
card determines the winner. If both have the same rank of highest card,
there is no winner.
- Straight: Any unbroken sequence, but not all of the same suit (e.g.
3C-4C-5C-6D-7C, or TG-JC-QC-KS-CG). If two players have a straight, then
the rank of the highest card determines the winner. If both highest cards
have the same rank, there is no winner.
- Three of a Kind: Three cards of the same rank together with two odd
cards (e.g. 7C-7S-7D-3C-9C). If two players have three of a kind, then
the rank of the three identical cards determines the winner.
- Two Pairs: Two cards of the same rank, together with another two
cards of equal rank, and one odd card (e.g. 8C-8D-3C-3S-QG). If two
players have two pairs, then the rank of the odd card involved determines
the winner. If still unresolved, there is no winner.
- One Pair: Two cards of the same rank, together with three odd cards
(e.g. 5C-5G-3S-7D-KS). If two players have one pair, then the rank of the
pair determines the winner. If the pairs are of the same rank, there is
no winner.
- One Card: If no player has any winning combination, then the player
with the highest ranked card in their hand is the winner. If that does
not resolve the issue, there is no winner.
Your Task:
Write a program that reads in a
sequence of pairs of choker hands, and for each prints the winner.
The description of a hand consists of the name of the player (a
sequence of between 1 and 20 letters) then a dash, then ten characters
representing the hand as dealt. For each pair of hands, print the
names of the two players involved (in the order in which they appeared),
separated by the sequence " vs ", followed by a colon and a single space,
then either the string "No Winner" or the name of the winner followed by
a space and "Wins".
There will be no blank lines in
the input. The end of the input will be signalled by a line containing
the string "END" and nothing else. In names, case is not significant;
in cards, only capitals will be used.
Sample Input
Joey-1C3S2G5D4D
Clucky-QDKDQSKSJS
Bill-9D6D5D3D2G
Sally-TC3C5S7D4G
Clucky-TDJDQDKDCD
Herbert-CSTSQSKSJS
Henry-TCJCQCKCCC
Herbert-CSTSQSKSJS
END
Sample Output
Joey vs Clucky: Joey Wins
Bill vs Sally: Sally Wins
Clucky vs Herbert: No Winner
Henry vs Herbert: Henry Wins
End of Problem