TopCoder problem "BridgePts" used in SRM 257 (Division II Level Two)

Problem Statement

    A deck of cards contains 52 cards. Each card has a suit (Clubs,Diamonds,Hearts,Spades) and a value (Ace,2,3,...,9,10,Jack,Queen,King). In the game of bridge a hand consists of 13 cards from the deck.

A player needs to evaluate his hand, giving it a point value. The standard method is as follows: count 4 points for each Ace, 3 points for each King, 2 points for each Queen, and 1 point for each Jack. For each suit, count 1 point if the hand contains exactly two cards of that suit, 2 points if exactly one card, and 3 points if the hand contains no cards of that suit. The point value of the hand is the sum of all these points.

Create a class BridgePts that contains a method pointValue that is given a int[] hand and that returns the point value of the hand.

Each element of hand indicates a card. The clubs are numbered 1 to 13, the diamonds are 14 to 26, the hearts are numbered 27 to 39, and the spades are numbered 40 to 52. Within each suit, the cards are numbered in the order Ace, 2, 3, ..., 9, 10, Jack, Queen, King. So, for example, the King of Hearts is numbered 39 and the Ace of Spades is numbered 40.



Method signature:int pointValue(int[] hand)
(be sure your method is public)


-hand will contain exactly 13 elements, all distinct.
-Each element of hand will have a value between 1 and 52 inclusive.


Returns: 19
This hand contains all diamonds, so it has one Ace, one King, one Queeen, and one Jack, and it contains no cards in three suits. So its point value is 4 + 3 + 2 + 1 + 3 + 3 + 3 = 19.
Returns: 0
This hand contains only 2's, 3's, 4's and one 5. It has 3 or 4 cards in each suit.

Problem url:

Problem stats url:




PabloGilberto , lbackstrom , brett1479 , Olexiy

Problem categories:

Simple Math, Simple Search, Iteration