ClientsList
SRM 227 · 2005-01-22 · by erinn
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
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.
{"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.
{"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.
{"Kelly, Anthony", "Kelly Anthony", "Thompson, Jack"}
Returns: { "Kelly Anthony", "Anthony Kelly", "Jack Thompson" }
Be careful to properly identify first name versus last name!
{"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" }
{"Jacobs, Peter"}
Returns: { "Peter Jacobs" }
{"Banks, Cody", "Cody Banks", "Tod Wilson"}
Returns: { "Cody Banks", "Cody Banks", "Tod Wilson" }
Notice that two identical names can appear in the list.
{"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.
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