TopCoder problem "Kings" used in TCHS07 Alpha 3 (Division I Level One)



Problem Statement

    

You are given a String[] names where each element is the name of a king who ruled the country. The kings are given in chronological order. Return a String[] containing the kings in the same order, but with their names changed as follows. If the name of a king is unique in the given list, leave his name unchanged. Otherwise, add a single space followed by the king's chronological number among all kings with the same name. The numbering should start from 1, and numbers must have no leading zeroes. For example, if there are two "William"s, the first one in the list would be "William 1" and the second would be "William 2".

 

Definition

    
Class:Kings
Method:enumerate
Parameters:String[]
Returns:String[]
Method signature:String[] enumerate(String[] names)
(be sure your method is public)
    
 

Constraints

-names will contain between 1 and 50 elements, inclusive.
-Each element of names will contain between 1 and 50 characters, inclusive.
-Each element of names will contain only uppercase letters ('A'-'Z').
 

Examples

0)
    
{"WILLIAM", "GEORGE", "PAUL", "GEORGE", "GEORGE", "WILLIAM"}
Returns: {"WILLIAM 1", "GEORGE 1", "PAUL", "GEORGE 2", "GEORGE 3", "WILLIAM 2" }
1)
    
{"OLE", "BJORN", "OLE", "GUNNAR", "LUDVIG", "CHRISTIAN", "LUDWIG",
"KARL", "CHRISTIAN", "LUDWIG"}
Returns: 
{"OLE 1",
"BJORN",
"OLE 2",
"GUNNAR",
"LUDVIG",
"CHRISTIAN 1",
"LUDWIG 1",
"KARL",
"CHRISTIAN 2",
"LUDWIG 2" }
2)
    
{"BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB",
"BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB",
"BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB",
"BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB",
"BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB", "BOB",
"BOB", "BOB", "BOB", "BOB", "BOB"}
Returns: 
{"BOB 1",
"BOB 2",
"BOB 3",
"BOB 4",
"BOB 5",
"BOB 6",
"BOB 7",
"BOB 8",
"BOB 9",
"BOB 10",
"BOB 11",
"BOB 12",
"BOB 13",
"BOB 14",
"BOB 15",
"BOB 16",
"BOB 17",
"BOB 18",
"BOB 19",
"BOB 20",
"BOB 21",
"BOB 22",
"BOB 23",
"BOB 24",
"BOB 25",
"BOB 26",
"BOB 27",
"BOB 28",
"BOB 29",
"BOB 30",
"BOB 31",
"BOB 32",
"BOB 33",
"BOB 34",
"BOB 35",
"BOB 36",
"BOB 37",
"BOB 38",
"BOB 39",
"BOB 40",
"BOB 41",
"BOB 42",
"BOB 43",
"BOB 44",
"BOB 45",
"BOB 46",
"BOB 47",
"BOB 48",
"BOB 49",
"BOB 50" }
3)
    
{"SEAN"}
Returns: {"SEAN" }
4)
    
{"IAMUNIQUE", "METOO", "ANDME", "ANDMETOO"}
Returns: {"IAMUNIQUE", "METOO", "ANDME", "ANDMETOO" }

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10729&pm=7607

Writer:

gevak

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Simple Search, Iteration, String Manipulation