TopCoder problem "XBallGame" used in SRM 302 (Division II Level Two)



Problem Statement

    

Fans of the game X-ball frequently use the official players' stats. These stats are presented as a list of players' names and the positions they can play. If a player can play at several positions, he is shown in the list once for each position.

The fans want to get the statistics in a new format. In the old format, each element of the list contained a single player and a single position played by that player. In the new format, each element of the list will contain a single player and all the positions that the player can play. The new list must contain the same number of elements as the old one, and players must appear in the same order as before. Each element of the new list must contain the name of the player, a '-' character, and a comma-separated list of all the positions the player can play. The first position must be the same position that was in the corresponding element of the old list, and the other positions must be sorted in alphabetical order.

Old format stats:  |  New format stats:
John-DH            |  John-DH,RP,SP         
Jack-SP            |  Jack-SP               
Sam-OF             |  Sam-OF                
John-SP            |  John-SP,DH,RP         
John-RP	           |  John-RP,DH,SP         

You will be given a String[] placeboard containing the statistics in the old format. Each element will contain a player's name and an abbreviation of the player's position in the form "Name-Position" (quotes for clarity). Return the list after converting it to the new format.

 

Definition

    
Class:XBallGame
Method:newStatistics
Parameters:String[]
Returns:String[]
Method signature:String[] newStatistics(String[] placeboard)
(be sure your method is public)
    
 

Notes

-Note that the names of the players are case-sensitive.
 

Constraints

-placeboard will contain between 1 and 50 elements, inclusive.
-Each element of placeboard will contain between 4 and 23 characters, inclusive.
-Each element of placeboard will be in the format "Name-Position" without any leading or trailing spaces.
-Position will consist of two upper-case letters ('A'-'Z').
-Name will contain between 1 and 20 letters ('A'-'Z', 'a'-'z'), inclusive.
-All elements of placeboard will be distinct.
 

Examples

0)
    
{"John-DH", 
 "Jack-SP", 
 "Sam-OF", 
 "John-SP", 
 "John-RP"}
Returns: {"John-DH,RP,SP", "Jack-SP", "Sam-OF", "John-SP,DH,RP", "John-RP,DH,SP" }
1)
    
{"John-DH", 
 "Jack-SP", 
 "Sam-OF", 
 "John-SP", 
 "John-RP", 
 "John-RA", 
 "John-RZ", 
 "Jack-OF", 
 "Sam-SP"}
Returns: 
{"John-DH,RA,RP,RZ,SP",
"Jack-SP,OF",
"Sam-OF,SP",
"John-SP,DH,RA,RP,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:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=9823&pm=6387

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , brett1479 , legakis , Olexiy

Problem categories:

Brute Force, String Manipulation