Statistics

Problem Statement for "NameCheck"

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.

Definition

Class:
NameCheck
Method:
formatList
Parameters:
String[]
Returns:
String[]
Method signature:
String[] formatList(String[] namelist)
(be sure your method is public)

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

  1. {"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.

  2. {"Doug G.","GG WALNUT DOUG", "AB. JONES", "A. BOB J.", "Gg DouG", "GG DOUG"}

    Returns: { "Gg Walnut Doug", "Gg Doug", "Gg Doug" }

  3. {"A BIG Mess", "A. Big Mess.Mess", "ABig","M.MESS"}

    Returns: { }

  4. {"A. . Bo"," C. D. Eo","F. G.Ho","I. J. KO"}

    Returns: { "I. J. Ko" }

  5. {"Abracadabra BeautifulBABE cassandra"}

    Returns: { "Abracadabra Beautifulbabe Cassandra" }

  6. {"A BeautifulBABE cassandra"," DonPotter James"}

    Returns: { }

  7. {"A. BeautifulBABE. cassandra","DonPotter James"}

    Returns: { "Donpotter James" }

  8. {"A. abcdefghijklmNopqrstuvwxyzabc Lu"}

    Returns: { "A. Abcdefghijklmnopqrstuvwxyzabc Lu" }

  9. {"Ab. Able","Ab Able","AbAble","D. J. xY"}

    Returns: { "Ab Able", "D. J. Xy" }

  10. {"A B C D e f g h i j l m n o p q r s t u v w","abcdefg hijkl.m nop"}

    Returns: { }

  11. {"ABCDefg hi jl","abcdefg .hijklm nop"}

    Returns: { "Abcdefg Hi Jl" }

  12. {"A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc","A. Bc"," A. Bc","A.Bc","A Bc","A. Bc","A. B c","A. Bc ","A. Bc","A. Bc"," A. Bc"}

    Returns: { "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc", "A. Bc" }

  13. {"Ab. Able","Ab Able","AbAble","DxY","C. A. R. Hoare"}

    Returns: { "Ab Able" }

  14. {"A. AbleZ","ab Able","Aaaa aa a.","AAAA A."}

    Returns: { "A. Ablez", "Ab Able" }

  15. {"A. AbleZ","ab Able","Aaaa aa a.","AAAA AaA"}

    Returns: { "A. Ablez", "Ab Able", "Aaaa Aaa" }

  16. {"Ab Ab"}

    Returns: { "Ab Ab" }

  17. {"A. Bc","B. Bc","C. Bc","D. Bc","E. Bc","F. Bc","G. Bc","H. Bc","IA. Bc","J. Bc","K. Bc","L. Bc","M. Bc","N. Bc","O. Bc","P. Bc","Q. Bc","R. Bc","S. Bc","T. Bc","U. Bc","V. Bc","W. Bc","X. Bc","Y. Bc","Z. Bc","A. Bc","B. Bc","C. Bc","D. Bc","E. Bc","F. Bc","G. Bc","H. Bc","I. Bc","J. Bc","K. Bc","L. Bc","M. Bc","N. Bc","O. Bc"," P. Bc","Q.Bc","R Bc","S. Bc","T. B c","U. Bc ","V. Bc","W. Bc"," X. Bc"}

    Returns: { "A. Bc", "B. Bc", "C. Bc", "D. Bc", "E. Bc", "F. Bc", "G. Bc", "H. Bc", "J. Bc", "K. Bc", "L. Bc", "M. Bc", "N. Bc", "O. Bc", "P. Bc", "Q. Bc", "R. Bc", "S. Bc", "T. Bc", "U. Bc", "V. Bc", "W. Bc", "X. Bc", "Y. Bc", "Z. Bc", "A. Bc", "B. Bc", "C. Bc", "D. Bc", "E. Bc", "F. Bc", "G. Bc", "H. Bc", "I. Bc", "J. Bc", "K. Bc", "L. Bc", "M. Bc", "N. Bc", "O. Bc", "S. Bc", "V. Bc", "W. Bc" }

  18. { "A.b aaa" }

    Returns: { }

  19. { "hello world " }

    Returns: { }

  20. { "AAAA J. BBB CCC" }

    Returns: { }

  21. { "G.g Henry" }

    Returns: { }

  22. { "David G. Rydh" }

    Returns: { "David G. Rydh" }

  23. { ".A aaa" }

    Returns: { }

  24. { "bla bla " }

    Returns: { }

  25. { "Cg Doug " }

    Returns: { }

  26. { " Viktoras Jucikas" }

    Returns: { }

  27. { "Hey Jack " }

    Returns: { }

  28. { ".. Lo", "J. Lo" }

    Returns: { "J. Lo" }

  29. { "A. B. C" }

    Returns: { }

  30. { "Robert Henry Thomas Jones" }

    Returns: { }

  31. { "b. b. mac" }

    Returns: { "B. B. Mac" }

  32. { "x.x soso" }

    Returns: { }

  33. { "ALPHABET BOMB abcdefghijklmnopqrstuvwxyz", "period. Period", "P. Eriod", " space bar bomb ", "alphabet bomb ABCDEFGHIJKLMNOPQRSTUVWXYZ", "bufferoverrunlalalalalalalala", "zeeky BOOGY doog", "buffer OVERRUN lalalalalalalalalalalalalalalallal", "it's illegal", " jkhfkahf ", "BOO yah", "honkhonk HONKHONK HonKHonK", "b. ANG", "throw me the heck out", "buffer OVERRUN lalalalalalalalalalalalalalalalla ", "Zeeky H. Bomb" }

    Returns: { "Alphabet Bomb Abcdefghijklmnopqrstuvwxyz", "P. Eriod", "Alphabet Bomb Abcdefghijklmnopqrstuvwxyz", "Zeeky Boogy Doog", "Buffer Overrun Lalalalalalalalalalalalalalalallal", "Boo Yah", "Honkhonk Honkhonk Honkhonk", "B. Ang", "Zeeky H. Bomb" }

  34. { "Hey Ja^ck" }

    Returns: { }


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: