POKER - Poker

no tags 

In poker, you have 5 cards. There are 10 kinds of poker hands (from highest to lowest):

  • royal flush - ace, king, queen, jack and ten, all in the same suit.
  • straight flush - five cards of the same suit in sequence, such as 10, 9, 8, 7, 6 of clubs; ace can be counted both as the highest card or as the lowest card - A, 2, 3, 4, 5 of hearts is a straight flush. But 4, 3, 2, A, K of hearts is not a straight flush - it's just a flush.
  • four of a kind - four cards of the same rank, such as four kings.
  • full house - three cards of one rank plus two cards of another rank.
  • flush - five cards of the same suit (but not a straight flush).
  • straight - five cards in order - just like the straight flush, but mixed suits.
  • three of a kind - three cards of one rank and two other cards.
  • two pairs - two cards of one rank, two cards of another rank, and one more card.
  • pair - two cards of the same rank.
  • high card - none of the above.

Write a program that will help you play poker by telling you what kind of hand you have.

Input

The first line of input contains the number of test cases (no more than 20). Each test case consists of one line - five space separated cards. Each card is represented by a two-letter (or digit) word. The first character is the rank (A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3 or 2), the second character is the suit (S, H, D, C standing for spades, hearts, diamonds and clubs). The cards can be in any order (but they will not repeat).

Output

For each test case output one line describing the type of a hand, exactly like in the list above.

Example

Input:
3
AH KH QH TH JH
KH 5S 3C 5C 7D
QH QD 2S QC 2C

Output:
royal flush
pair
full house

hide comments
liupan2010: 2023-05-21 04:42:22

@Haijun Deng

I got WA,but my program can past your test cases.

Why?

aditiwari: 2016-05-28 10:55:14

accepting simple nested if else in 0.00!! :D

sumbayak_ae: 2016-04-16 08:56:16

@muhamed_hafez: there is no "Joker" in the input constraint

Mohammed Hafez: 2016-03-04 12:30:21

Please note that straight is "five cards of sequential RANK".
So, "7, 8, 9, 10, Jack" -> straight
"8, 9, 10, Jack, Queen" -> straight
"9, 10, Jack, Queen, King" -> straight
"10, Jack, Queen, King, Ace" -> straight (if not flush already, in which case it's royal flush)
"Ace, 2, 3, 4, 5" -> straight (because ace can be considered highest or lowest rank)
"7, 8, 9, 10, Ace" -> NOT straight

@sumbayak_ae, thanks for pointing out

Last edit: 2016-05-06 20:23:45
chin: 2015-07-05 12:21:12

got clrd on if's and else's!!!...accepted!!!

Nezar Ali: 2014-01-30 12:02:47

@Haijun Deng
Thaaaaaanx for the test cases! :D

Haijun Deng: 2013-06-26 13:53:08

for those who got WA, please test your program with these follow case:
Input:
11
AH KH QH TH JH
AD 2D 3D 4D 5D
2S 2H 2D 2C 4D
QH QD 2S QC 2C
4C 3C 2C AC KC
4C 9C TC AC KC
5H AS 2C 3D 4C
5H 5D 5C 7H KS
2H 2S 4C 4S 5D
KH 5S 3C 5C 7D
AH 4S 9C TD 3H

Output:
royal flush
straight flush
four of a kind
full house
flush
flush
straight
three of a kind
two pairs
pair
high card

nitin KR shukla: 2012-09-26 03:34:54

same here as Zhiang, don't know what's wrong ;(

!@#$: 2011-12-22 20:57:28

is dere any special case ???
dont know why i am getting wrong answer... :(

Rudolf Brisuda: 2010-11-13 19:30:21

not hard

Last edit: 2010-08-07 21:44:21

Added by:Tomek Czajka
Date:2005-05-03
Time limit:7s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6 VB.NET
Resource:Purdue Programming Contest Training