PokerDeck
SRM 265 · 2005-09-27 · by HardCoder
Problem Statement
You want to play poker with some friends, but your little sister has been using all the cards in the house to perform magic tricks. It seems the only trick she has perfected is a disappearing act which makes it impossible to find a complete deck of cards. You and your friends gather as many cards as you are able to find and put them into a single deck. This, however, might change the probability of getting certain poker hands. Given a
Each element in decks is a list of cards separated by spaces. Each card will be in the format <face><suit> where <face> is one of the 13 face values, listed in increasing consecutive order ( 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A ) and <suit> is one of ( C, D, H, S ).
The possible hands from a combined deck are:
"ONE PAIR" - two of the five cards have the same face value (2C 4S 5H 8C 8D)
"TWO PAIR" - two of one face value and two of a different face value (4H 4S 5H 8C 8D)
"THREE OF A KIND" - three cards of the same face value (2C 4S 8H 8C 8D)
"FOUR OF A KIND" - four cards of the same face value (2C 8S 8H 8C 8D)
"FULL HOUSE" - three of one face value and two of a different face value (8H 8C 8D 4C 4S)
"FLUSH" - five cards of the same suit (2C 5C 7C QC AC)
"STRAIGHT" - five cards with consecutive face values (8C 9S 10C JH QD)
The ace may be used as the low card in a straight (AD 2C 3S 4C 5H)
However, wrapping is not allowed (QC KC AC 2D 3C)
"STRAIGHT FLUSH" - matches both a FLUSH and a STRAIGHT (7H 8H 9H 10H JH)
"ROYAL FLUSH" - ten, jack, queen, king, ace of the same suit (10S JS QS KS AS)
"FIVE OF A KIND" - all five cards with the same face value (6C 6D 6C 6S 6H)
"NOTHING" - a hand that does not match any of these combinations (2C 7D 8H 10C AS)
Since the order in which cards are dealt does not matter, a hand containing ( QD 9S JH 8C 10C ) is identical to ( 8C 9S 10C JH QD ) and both would be classified as a "STRAIGHT". A hand that matches more than one of the descriptions listed above is classified with the name that appears lowest. For instance, the hand ( 3C 3D 3H KC KD ) would be classified as a "FULL HOUSE" even though it also matches the descriptions for "THREE OF A KIND" and "ONE PAIR".
Notes
- The same card may appear multiple times in an element of decks
Constraints
- decks will have between 1 and 50 elements, inclusive.
- Each element of decks will have between 2 and 50 characters, inclusive.
- Each element of decks will contain valid cards with a single space between cards.
- The first character and the last character of each element of decks will not be a space.
- A valid card will be formatted as
will be one of ( 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A ). will be one of ( C, D, H, S ). - decks will represent at least 5 cards.
{"AC 2C 3C 4C 5C 6C 7C 8C 9C 10C JC QC KC",
"AD 2D 3D 4D 5D 6D 7D 8D 9D 10D JD QD KD",
"AH 2H 3H 4H 5H 6H 7H 8H 9H 10H JH QH KH",
"AS 2S 3S 4S 5S 6S 7S 8S 9S 10S JS QS KS"}
Returns: {"ROYAL FLUSH", "STRAIGHT FLUSH", "FOUR OF A KIND", "FULL HOUSE", "FLUSH", "STRAIGHT", "THREE OF A KIND", "TWO PAIR", "ONE PAIR", "NOTHING" }
This is a standard deck of cards, which will result in the following odds: ROYAL FLUSH: 4/2598960 STRAIGHT FLUSH: 36/2598960 FOUR OF A KIND: 624/2598960 FULL HOUSE: 3744/2598960 FLUSH: 5108/2598960 STRAIGHT: 10200/2598960 THREE OF A KIND: 54912/2598960 TWO PAIR: 123552/2598960 ONE PAIR: 1098240/2598960 NOTHING: 1302540/2598960
{"AS 2C 3C 4C 5C 7D 7H 8C 8D 8H 10S JS QS KS"}
Returns: {"FLUSH", "FULL HOUSE", "ROYAL FLUSH", "STRAIGHT", "TWO PAIR", "THREE OF A KIND", "ONE PAIR", "NOTHING" }
This deck results in the following odds: FLUSH: 1/2002 FULL HOUSE: 1/2002 ROYAL FLUSH: 1/2002 STRAIGHT: 1/2002 TWO PAIR: 27/2002 THREE OF A KIND: 54/2002 ONE PAIR: 660/2002 NOTHING: 1257/2002
{"10S 10S 10S 10S 10S 10S 10S 10S 10S 10S 10S 10S",
"JS JS JS JS JS JS JS JS JS JS JS JS JS JS JS JS JS",
"QS QS QS QS QS QS QS QS QS QS QS QS QS QS QS QS QS",
"KS KS KS KS KS KS KS KS KS KS KS KS KS KS KS KS KS",
"AS AS AS AS AS AS AS AS AS AS AS AS AS AS AS AS AS"}
Returns: {"FIVE OF A KIND", "ROYAL FLUSH", "FLUSH" }
{"2C 10S 10S 10S 10S 10S 10S 10S 10S 10S 10S 10S 10S",
"JS JS JS JS JS JS JS JS JS JS JS JS JS JS JS JS JS",
"QS QS QS QS QS QS QS QS QS QS QS QS QS QS QS QS QS",
"KS KS KS KS KS KS KS KS KS KS KS KS KS KS KS KS KS",
"AS AS AS AS AS AS AS AS AS AS AS AS AS AS AS AS AS"}
Returns: {"FOUR OF A KIND", "FIVE OF A KIND", "TWO PAIR", "THREE OF A KIND", "NOTHING", "ONE PAIR", "ROYAL FLUSH", "FLUSH" }
{"AS AS AS AS AS AS AS AS AS AS AS",
"AS AS AS AS AS AS AS AS AS AS AS",
"AS AS AS AS AS AS AS AS AS AS AS",
"2C 4C 6C 8C"}
Returns: {"NOTHING", "ONE PAIR", "THREE OF A KIND", "FOUR OF A KIND", "FIVE OF A KIND" }
Submissions are judged against all 59 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PokerDeck with a public method vector<string> getRanking(vector<string> decks) · 59 test cases · 2 s / 256 MB per case