Connection Status:
Competition Arena > NameCheck
SRM 179 · 2004-01-17 · by dgoodman · String Manipulation, String Parsing
Class Name: NameCheck
Return Type: String[]
Method Name: formatList
Arg Types: (vector<string>)
Problem Statement

Problem Statement

A user has entered a list of Strings. We must check each String to see if it meets our criteria for a "customer", and either reject the String or recapitalize and respace it to meet our standards.

Our formatting manual states:

  1. A well-formed customer consists of either 2 or 3 parts. The parts are separated by one or more spaces, but there are no leading spaces or trailing spaces. Each part must be a name or an initial, but the last part may not be an initial. An initial is a letter ('a-z' or 'A-'Z') followed by a period ('.') A name is a sequence of two or more letters ('a-z' or 'A'-'Z').

Our standard for recapitalizing a well-formed customer is that each name or initial should start with an uppercase letter and all other letters should be lowercase. Our standard for respacing a well-formed customer is that any extra spaces between parts should be removed leaving exactly one space between adjacent parts.

Create a class NameCheck that contains a method formatList that is given a String[] namelist and that returns a String[] that includes all the well-formed customers, properly recapitalized and respaced. They should appear in the same order as in the original namelist.

Constraints

  • namelist will contain between 1 and 50 elements inclusive.
  • Each element of namelist will contain between 1 and 50 characters inclusive.
  • Each character in each element of namelist will be an ASCII character (32-126).
Examples
0)
{"Doug#as good","bArneY R.", "bArneY   Rubble"," Bob Stone", "Bob B. J. Toms","J. Lo"}
Returns: { "Barney Rubble",  "J. Lo" }

"Doug#as good" is not well-formed because Doug#as is not a name or initial. "bArneY R." is not well-formed because it does not end with a name. " Bob Stone" is not well-formed because it starts with a space. "Bob B. J. Toms" is not well-formed because it has 2 names and 2 initials. "bArneY Rubble" is well-formed, being a first name followed by a last name. "J. Lo" is well-formed, being a first initial followed by a last name.

1)
{"Doug G.","GG WALNUT DOUG", "AB. JONES", "A. BOB J.", "Gg DouG", "GG DOUG"}
Returns: { "Gg Walnut Doug",  "Gg Doug",  "Gg Doug" }
2)
{"A BIG Mess", "A. Big Mess.Mess", "ABig","M.MESS"}
Returns: { }
3)
{"A.                  .           Bo"," C.       D.   Eo","F.       G.Ho","I. J.   KO"}
Returns: { "I. J. Ko" }
4)
{"Abracadabra   BeautifulBABE cassandra"}
Returns: { "Abracadabra Beautifulbabe Cassandra" }

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

Coding Area

Language: C++17 · define a public class NameCheck with a public method vector<string> formatList(vector<string> namelist) · 34 test cases · 2 s / 256 MB per case

Submitting as anonymous