Connection Status:
Competition Arena > ClientsList
SRM 227 · 2005-01-22 · by erinn · Sorting, String Manipulation, String Parsing
Class Name: ClientsList
Return Type: String[]
Method Name: dataCleanup
Arg Types: (vector<string>)
Problem Statement

Problem Statement

Your company has just undergone some software upgrades, and you will now be storing all of the names of your clients in a new database. Unfortunately, your existing data is inconsistent, and cannot be imported as it is. You have been tasked with writing a program to cleanse the data.

You are given a String[], names, which is a list of the names of all of your existing clients. Some of the names are in "First Last" format, while the rest are in "Last, First" format. You are to return a String[] with all of the names in "First Last" format, sorted by last name, then by first name.

Constraints

  • names will contain between 1 and 50 elements, inclusive.
  • Each element of names will be of the form "First Last" or "Last, First" (quotes added for clarity).
  • Each first and last name will begin with a single capital letter 'A'-'Z', and the remaining letters will be lower case 'a'-'z'.
  • Each element of names will contain between 3 and 50 characters, inclusive.
Examples
0)
{"Joe Smith", "Brown, Sam", "Miller, Judi"}
Returns: { "Sam Brown",  "Judi Miller",  "Joe Smith" }

The last names, in order, are Brown, Miller, Smith. We rearrange each name to be in the proper format also.

1)
{"Campbell, Phil", "John Campbell", "Young, Warren"}
Returns: { "John Campbell",  "Phil Campbell",  "Warren Young" }

Notice here how we sort by first name when the last names are the same.

2)
{"Kelly, Anthony", "Kelly Anthony", "Thompson, Jack"}
Returns: { "Kelly Anthony",  "Anthony Kelly",  "Jack Thompson" }

Be careful to properly identify first name versus last name!

3)
{"Trevor Alvarez", "Jackson, Walter", "Mandi Stuart",
 "Martin, Michael", "Peters, Tammy", "Richard Belmont",
 "Carl Thomas", "Ashton, Roger", "Jamie Martin"}
Returns: { "Trevor Alvarez",  "Roger Ashton",  "Richard Belmont",  "Walter Jackson",  "Jamie Martin",  "Michael Martin",  "Tammy Peters",  "Mandi Stuart",  "Carl Thomas" }
4)
{"Jacobs, Peter"}
Returns: { "Peter Jacobs" }
5)
{"Banks, Cody", "Cody Banks", "Tod Wilson"}
Returns: { "Cody Banks",  "Cody Banks",  "Tod Wilson" }

Notice that two identical names can appear in the list.

6)
{"Mill, Steve", "Miller, Jane"}
Returns: { "Steve Mill",  "Jane Miller" }

Notice that when shorter names precede longer names alphabetically, when the shorter name is a substring of the longer.

Submissions are judged against all 31 archived test cases, of which 7 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ClientsList with a public method vector<string> dataCleanup(vector<string> names) · 31 test cases · 2 s / 256 MB per case

Submitting as anonymous