CIST 1400 (Section 401)
Introduction to Computer Programming
Summer 2001 (Second Day Session)
Due: Wednesday, August 8,
2001
Introduction
The player with the
highest-ranking hand wins the card game of poker. Each hand has five cards. Each card has a suit (one of clubs, diamonds, hearts and spades) and a rank (one of 2, 3, 4,
, 10, jack,
queen, king, ace).
In this problem, the input
data will contain specification of the five cards in a poker hand, and your
program is to determine the rank associated with the hand.
The specification of each card is given by two characters entered without any separation between them. The first character of a pair indicates the rank of the card. For the ranks of 2 through 9, the characters 2 through 9 are used. For 10, jack, queen, king, and ace, the characters T, J, Q, K, and A are used. The second character of the pair indicates the suit of the card. C is used for clubs, D for diamonds, H for hearts, and S for spades. Thus the pair AH specifies the ace of hearts, the pair 2C specifies the two of clubs, and the pair TD specifies the ten of diamonds.
Each poker hand has one of
the ranks described below. These are
given in order from the lowest-ranking hand to the highest-ranking hand.
High card. If none of the other cases
apply, the hand is ranked by the highest ranked card in the hand. Example: 6S, 8D, 9D, JH, KS.
One pair. A hand with two cards of the
same rank. Example: 6S, 6D, 3C, TC, AS.
Two pair. A hand with two pairs of
cards of the same rank. Example: 2C,
2D, 6H, 6S, AD.
Three of a kind. A hand containing three cards
with the same rank. Example: 2S, 2A,
2D, 4C, 4H.
Straight. A hand containing five cards
in sequence. Example: 8S, 9C, TH, JC, QD.
Flush. A hand in which all five cards have the same suit. Example:
2C, 5C, 7C, 8C, AC.
Full house. A hand containing three cards
of the same rank, and the remaining two cards with the same rank. Example: 2C, 2H, 2D, 7H, 7S.
Four of a kind. A hand containing four cards
of the same rank. Example: 7D, 7H, 7C,
7S. AD.
Straight flush. A hand containing a straight
in which each of the cards is of the same suit. Example: 6D, 7D, 8D, 9D, TD.
Write a program that obtains
from the user the specification of the five cards in a poker hand, then
determines and displays the rank associated with that poker hand. An acceptable format for the input and
output is shown in the sample execution (below).
Sample
Execution
The input and output from
several typical executions of the program is shown below. Make certain you test your program with
various input data to ensure you have correctly solved the problem.
Enter the specification of the five cards in the hand: AS 2D AC 2H 2C
Hand rank: full house
Enter the specification of the five cards in the hand: 2H 3H 7H 9H AH
Hand rank: flush
Enter the specification of the five cards in the hand: 4D 7D 9H 4S 7C
Hand
rank: two pair