TopCoder problem "CustomerStatistics" used in SRM 287 (Division II Level One)



Problem Statement

    

You will be given a String[] customerNames, containing a list of customer names extracted from a database. Your task is to report the customers that occur more than once in this list, and the number of occurrences for each of the repeated customers.

Your method should return the report as a String[]. Each element in this String[] should be of the form "NAME OCCURS", where NAME is the name of one customer and OCCURS is the number of times his name occurs in customerNames. Sort the result in alphabetical order by customer name.

 

Definition

    
Class:CustomerStatistics
Method:reportDuplicates
Parameters:String[]
Returns:String[]
Method signature:String[] reportDuplicates(String[] customerNames)
(be sure your method is public)
    
 

Constraints

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

Examples

0)
    
{"JOHN", "BOB", "JOHN", "BILL", "STANLEY", "JOHN"}
Returns: {"JOHN 3" }
The only repeated name is JOHN, and it occurs three times.
1)
    
{"YETTI", "YETTI", "YETTI", "BIGFOOT", "BIGFOOT"}
Returns: {"BIGFOOT 2", "YETTI 3" }
Note the sorting order.
2)
    
{"ANDREW", "BILL", "CINDY", "DOH", "ERGH", "FOO", "GOO", "HMPH"}
Returns: { }
No repeated names this time.
3)
    
{"THEONLYCUSTOMER"}
Returns: { }
Again, no repeats.
4)
    
{"A", "B", "A", "C", "A", "B", "A", "D", "D", "D"}
Returns: {"A 4", "B 2", "D 3" }

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=9808&pm=5975

Writer:

misof

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Sorting