Old tennis players love playing cards P41239


pdf   zip



The Russian Yevgeny Kafelnikov, born on 1974 in Sochi, was one of the top tennis players during the nineties. He earned 24 million dollars thanks to 26 single titles (including two Grand Slams) and 27 doubles titles (including four Grand Slams). After winning the Australian Open in 1995, he managed to reach the World Number 1 men’s singles ranking for six consecutive weeks. In the summer of the year 2000, he won the men’s singles Gold Medal for Russia at the Sydney Olympic Games. Two years later, Kafelnikov was part of the Russian team that won the Davis Cup for the first time.


But fame and money was not enough, and Kafelnikov decided to retire in 2004. He wanted to spend the next years to his real passion: playing cards. When he was a child, Yevgeny was fascinated by the atmosphere of poker tables. Some people say that he dreamed of smoking a big cigar while drinking a pint of black beer and betting huge amounts of money. Others say that the Russian player always wanted to wear fashionable poker glasses. Now, Yevgeny wants to participate in the next World Series of Poker that will be held in Caesar’s Hotel in Las Vegas.


As Kafelnikov studied at Saratov State University, there he met many crazy computer scientists that spent hours solving and submitting hard problems to their online contest server. So, he asks the help of some of those brilliant guys to improve his way of playing.


A poker deck contains 52 cards. Each card has a suit which is one of clubs, diamonds, hearts or spades. Each card also has a value which is one of 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king or ace. A poker hand consists of 5 cards dealt from the deck. Poker hands are ranked by the following partial order, from lowest to highest (for the sake of simplicity, some poker rules have been eliminated):

  • One Card: Hands which do not fit any higher category (all the values are different).
  • Pair: Two of the five cards in the hand have the same value.
  • Two Pairs: The hand contains two different pairs.
  • Three of a Kind: Three of the cards in the hand have the same value.
  • Full House: Three cards of the same value, the remaining two cards being a pair.
  • Poker: four cards with the same value.

Note that the value of the cards is irrelevant in this problem, in the sense that we consider a pair of aces as good as a pair of sevens.

The World Series of Poker are played in face-to-face games, where two players receive one card each at every turn. After receiving the card, the player can raise (increase the bet) or fold (just retire) depending on the given cards. Given a partial game, your task is to determine if Yevgeni should raise, fold or wait. Assume that Yevgeni can see the cards of his opponent.


Inputs consists of several cases. Every case begins with the number k of cards already given to the players, with 1 ≤ k ≤ 5. Follow the k cards that belong to Kafelnikov’s hand. Follow the k cards of his opponent. Each card is specified by two characters: the suite (C, D, H or S) and the value (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K or A). A special case of k=0 ends the input.


For every case, tell if Yevgeni should raise, fold or wait.

Public test cases
  • Input

    C3 H3 D3 S3   
    C7 H7 D7 S4   
    S2 D7
    C3 D3
    C2 D2 D3 H4 HK
    S3 S5 D8 H8 CQ


    Yevgeni should raise.
    Yevgeni should fold.
    Yevgeni should wait.
  • Information
    Miquel Moretó
    Official solutions
    User solutions