TopCoder problem "DictionarySorter" used in TCCC05 Qual 3 (Division I Level One)



Problem Statement

    In some languages (like Old English), the character set is very similar to the standard a-z set, but contains a few other characters. In this problem, you will write a sorter for a dictionary which contains the ash and thorn characters in addition to a-z. Ash will be represented in the input as "/ae" and should be treated as a single character which comes after 'a' but before 'b'. Thorn will be represented by "/th" and should be treated similarly, but sorted after 't' and before 'u'. Given a String[], words, sort the Strings, and return the result.
 

Definition

    
Class:DictionarySorter
Method:sort
Parameters:String[]
Returns:String[]
Method signature:String[] sort(String[] words)
(be sure your method is public)
    
 

Notes

-You should use the standard sorting rules. Find the first character for which two Strings differ, and return the one with the lower character in that position. If one String is a prefix of another, the shorter String should come first.
 

Constraints

-words will contain between 0 and 50 elements, inclusive.
-Each element of words will contain between 1 and 50 lowercase letters ('a'-'z') and slashes ('/').
-Each '/' will be followed by "ae" or "th".
 

Examples

0)
    
{"a","b","/ae","t","u","/th"}
Returns: { "a",  "/ae",  "b",  "t",  "/th",  "u" }
1)
    
{"aeleric","/aeleric","aelfred","alfred","/aelfred","/ae/th"}
Returns: { "aeleric",  "aelfred",  "alfred",  "/aeleric",  "/aelfred",  "/ae/th" }
2)
    
{"/the","quick","brown","fox","jumps","over","/ae","lazy","dog"}
Returns: 
{ "/ae",
 "brown",
 "dog",
 "fox",
 "jumps",
 "lazy",
 "over",
 "quick",
 "/the" }
3)
    
{"/ae","/ae/ae","t","t/th"}
Returns: { "/ae",  "/ae/ae",  "t",  "t/th" }

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=6525&pm=3505

Writer:

lars2520

Testers:

PabloGilberto , vorthys

Problem categories:

Sorting