TopCoder problem "OldestOne" used in SRM 177 (Division II Level Two)



Problem Statement

    Our student data is a mess! Each student is described with one String. At least a student's data always starts with her name, then her age, and then her address, and none of these is ever missing. The name and age are separated by one or more spaces and the age is separated from the address by one or more spaces. There may be leading and trailing spaces in a student's data.

A student's name always consists only of uppercase letters 'A'-'Z' and embedded (not leading or trailing) spaces. A student's age always consists of exactly 1, 2, or 3 digits, and its leading digit is not a zero. A student's address always contains at least one non-space character.

We need to find the name of the oldest student. If there are several, we want the one that appears earliest in the data. The name should include its embedded spaces (even if there are several consecutive embedded spaces), but no leading spaces and no trailing spaces.

Create a class OldestOne that contains a method oldest that is given a String[] data where each element is the data for a student, and that returns the name of the oldest student.

 

Definition

    
Class:OldestOne
Method:oldest
Parameters:String[]
Returns:String
Method signature:String oldest(String[] data)
(be sure your method is public)
    
 

Constraints

-data will contain between 1 and 50 elements inclusive
-Each element of data will contain between 5 and 50 characters inclusive
-Each character in each element of data will be an uppercase letter 'A'-'Z', a digit '0'-'9' or a space (' ').
-Each element of data will contain a name followed by an age and address, formatted as explained above, and may contain leading and trailing spaces.
-The name in each element will contain only uppercase letters 'A'-'Z' and embedded spaces.
-The age in each element will have no leading zeroes and will consist of between 1 and 3 digits inclusive.
 

Examples

0)
    
{"DOUG JONES 22 213 ALDEN LANE","   BOB     A SMITH  102 CLARK ST"}
Returns: "BOB     A SMITH"
Bob is clearly the oldest of these students. Note that the leading spaces and trailing spaces in the name are not included in the return, but the spaces embedded in the name must be preserved.
1)
    
{"DOUG JONES 102 213 ALDEN LANE","   BOB     A SMITH  102 CLARK ST",
 "A 1 999ELM"}
Returns: "DOUG JONES"
Now Doug Jones is 102 and is tied for oldest. A has an age of 1 (the 999 is part of his address). Bob is also 102, but comes later in the data than Doug.
2)
    
{"DOUG JONES 122 213 ALDEN LANE","   BOB     A SMITH  102 CLARK ST",
 "A 199 ELM"}
Returns: "A"
A has a one letter name, but is the oldest.
3)
    
{"   DOUG                 JONES   122 213 ALDEN LANE",
"   BOB     A SMITH                       102  3",
 " J O H N N Y           199 ELM"}
Returns: "J O H N N Y"
I don't know why Johnny likes to put spaces in his name, but we have to respect his wishes.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=1913

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4690&pm=1913

Writer:

dgoodman

Testers:

lbackstrom , brett1479

Problem categories:

String Parsing