TopCoder problem "TheBlackJackDivTwo" used in SRM 448 (Division II Level One)



Problem Statement

    

John and Brus are training for a card game tournament. There they will be playing Black Jack. Black Jack is played using a standard deck containing 52 distinct cards. Each card can be represented as a two-character string where the first character is the rank ('2' - '9' for ranks Two through Nine, 'T' for Ten, 'J' for Jack, 'Q' for Queen, 'K' for King and 'A' for Ace) and the second character is the suit ('S' for Spades, 'C' for Clubs, 'D' for Diamonds and 'H' for Hearts). For example, the Jack of Spades can be represented as "JS" and the Nine of Hearts as "9H".

Each time a player receives a card from the deck, his score increases by the card's value. Ranks Two through Ten have values of 2 - 10, respectively. Jacks, Queens and Kings each have a value of 10, and Aces have a value of 11.

Brus randomly shuffles the full card deck and gives John several cards from the top of the deck. You are given a String[] cards, where each element represents a single card given to John. Return John's score after this initial deal.

 

Definition

    
Class:TheBlackJackDivTwo
Method:score
Parameters:String[]
Returns:int
Method signature:int score(String[] cards)
(be sure your method is public)
    
 

Constraints

-cards will contain between 1 and 50 elements, inclusive.
-Each element of cards will contain exactly two characters, where the first character is '2'-'9', 'T', 'J', 'Q', 'K' or 'A', and the second character is 'S', 'C', 'D' or 'H'.
-All elements of cards will be distinct.
 

Examples

0)
    
{"4S", "7D"}
Returns: 11
The Four of Spades has a value of 4 and the Seven of Diamonds has a value of 7. The total score is 4 + 7 = 11.
1)
    
{"KS", "TS", "QC"}
Returns: 30
Each of the three cards has a value of 10.
2)
    
{"AS", "AD", "AH", "AC"}
Returns: 44
Each of the Aces has a value of 11.
3)
    
{"3S", "KC", "AS", "7C", "TC", "9C", "4H", "4S", "2S"}
Returns: 60

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13902&pm=10616

Writer:

Vasyl[alphacom]

Testers:

PabloGilberto , ivan_metelsky , Chmel_Tolstiy

Problem categories:

Simple Search, Iteration