TopCoder problem "PokerWish" used in SRM 21 (Division I Level Three , Division II Level Three)

Problem Statement

Class name: PokerWish
Method name: winChance
Parameters: String
Returns: int

Implement a class PokerWish, which contains a method winChance.  winChance
returns an int that is the maximum possible percentage chance a winning poker
hand will result from the input hand after one draw (one draw means any number
of cards between 0 and 5, inclusive, can by simultaneously replaced with cards
from the deck).  

The input will be of the form "CS,CS,CS,CS,CS" (no spaces), representing a
five-card poker hand, drawn from a standard playing deck.  C can take on the
values '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', or 'A'
representing the card rank and S can take on the values 'C', 'D', 'H', or 'S'
representing the suit of each card.  A standard playing deck contains 52 cards,
the thirteen possible card ranks (possible C values) in the four possible suits
(possible S values). 

A winning hand is defined as being either a straight or a flush.  The cards
have a defined order that is given by the list above ('2'-'A'); with the
exception that, in a hand, Ace ('A') can be the highest valued card or the
lowest valued card, but not both.  A straight consists of having five cards in
sequence (the cards in your hand can be rearranged to put them in order).
(Therefore a straight can be 5A234, 6789T, TJQKA, etc... but not QKA23 nor
23567).  A flush consists of having five cards of the same suit.  All other
types of standard poker hands are ignored.

You are allowed to exchange any number of cards with an equal number of cards
from the remaining deck exactly one time.  The remaining deck contains the
52-5=47 cards that are not in the original hand.  Following this rule, compute
the percentage chance of having a winning hand, assuming you replace the cards
such that your chances of getting a winning hand are maximized. Possible
replacement is the replacement of between 0 and 5 cards, inclusive, that
results in the highest chance of winning.  The returned percentage should be
truncated (fractional part dropped) to an int.

Here is the method signature (be sure your method is public):
int winChance(String hand);

*hand will be of the input for above and will contain 5 unique valid cards.
TopCoder will verify the input is valid.

"AS,4S,8S,3S,JC" returns 19  (best chance is to discard the club, hoping for a
"2S,3H,5C,4D,6H" returns 100 (this is a straight, and the player replaces
"8S,3H,5C,4D,6H" returns 17  (best chance is to discard the 8, hoping for a 2
or 7)
"8S,QD,5C,4D,6H" returns 8   (missing the 7 for a straight)
"AS,AH,AC,KD,KH" returns 1


Method signature:int winChance(String param0)
(be sure your method is public)

Problem url:

Problem stats url:




Problem categories: