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.

 

Definition

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

Constraints

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

Examples

0)
    
{25,14,15,16,17,18,19,20,21,22,23,24,26}
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.
1)
    
{2,3,4,15,18,28,29,30,41,42,43,16,17}
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:

http://www.topcoder.com/stat?c=problem_statement&pm=3494

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=8005&pm=3494

Writer:

dgoodman

Testers:

PabloGilberto , lbackstrom , brett1479 , Olexiy

Problem categories:

Simple Math, Simple Search, Iteration