TopCoder problem "BridgeSort" used in SRM 183 (Division II Level Two)



Problem Statement

    A deck of cards contains 52 cards. Each card has a suit (Clubs, Diamonds, Hearts, or Spades) and a value (2, 3, ..., 9, 10, Jack, Queen, King, or Ace).

In the game of bridge a hand consists of 13 or fewer cards from the deck. The values of the cards are ordered as shown above, with Ace having the highest value. Suppose that hand is given as a String giving the cards in the hand. Each card is represented by a suit character C, D, H, or S followed by a value character 2, 3, ..., 9, T, J, Q, K, or A. There are no spaces separating adjacent cards in hand.

Create a class BridgeSort that contains a method sortedHand that is given a String hand and that returns the String that represents the hand in sorted order. The proper order is to list all the cards that are Clubs, then all the Diamonds, then all the Hearts, and finally all the Spades, with the cards within each suit listed in order of ascending value.

 

Definition

    
Class:BridgeSort
Method:sortedHand
Parameters:String
Returns:String
Method signature:String sortedHand(String hand)
(be sure your method is public)
    
 

Constraints

-hand will contain an even number of characters between 2 and 26 characters inclusive.
-hand will contain a sequence of cards, each being a suit character followed by a value character as described in the problem statement.
-The cards in hand will be distinct.
 

Examples

0)
    
"HAH2H3C4D5ST" 
Returns: "C4D5H2H3HAST"
This hand contains the 4 of Clubs, which must come before all the other cards because Clubs comes before all the other suits. The 5 of Diamonds is next because Diamonds are the next suit. Next come the three Heart cards, in order of ascending value, namely 2 then 3 then Ace (which is represented by the A). Finally the 10 of Spades is last because of its suit.
1)
    
"H3SAHA"
Returns: "H3HASA"

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4735&pm=2336

Writer:

dgoodman

Testers:

lbackstrom , brett1479

Problem categories:

Sorting