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.



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


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


-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.


Returns: {"John-DH,RP,SP", "Jack-SP", "Sam-OF", "John-SP,DH,RP", "John-RP,DH,SP" }
"Sam-SP,OF" }
{"PFwL-GE", "PFwL-EV","agXL-SR", "PFwL-CS", "PFwL-FE", "PFwL-MS", "agXL-VS", "agXL-AL", "PFwL-BI", "PFwL-DK", 
 "PFwL-MW", "PFwL-DS", "agXL-XJ", "agXL-PJ", "agXL-CK", "PFwL-KI", "agXL-KP", "agXL-EL", "PFwL-EA"}
{"a-AA", "a-ZZ"}
Returns: {"a-AA,ZZ", "a-ZZ,AA" }

Problem url:

Problem stats url:




PabloGilberto , brett1479 , legakis , Olexiy

Problem categories:

Brute Force, String Manipulation