TopCoder problem "DateFormat" used in SRM 354 (Division I Level One , Division II Level Two)



Problem Statement

    

In the US, dates are usually written starting with the month, but in Europe, they are usually written starting with the day. So, January 16 will be written as "01/16" in the US and as "16/01" in Europe.

You have a list of dates for the next year and it is known that the given dates are listed in strictly increasing order. Unfortunately, the list was populated by different people and it can contain dates in both formats. You want to convert all dates into the US format.

You will be given a String dateList. First, you should concatenate all elements of dateList and consider it as one String. The conjoint dateList will contain a space-separated list of the dates. Each date will be in the form "XX/XX" (quotes for clarity), where each X is a digit. Convert the dates (without changing the order of the list) so that each date is in the US format and the list is in strictly increasing order. Note that in the original list, the format in which certain dates were written might be ambiguous. You may interpret those dates as being in either format as long as the final list is in strictly increasing order. Return the result as a single String in the same format as the original. If there are several solutions possible return one that comes first lexicographically. If it is impossible to obtain a strictly increasing list of dates, return an empty String.

 

Definition

    
Class:DateFormat
Method:fromEuropeanToUs
Parameters:String[]
Returns:String
Method signature:String fromEuropeanToUs(String[] dateList)
(be sure your method is public)
    
 

Notes

-Next year is 2008, a leap year. So, February 29 is a valid date.
 

Constraints

-dateList will contain between 1 and 50 elements, inclusive.
-Each element of dateList will contain between 1 and 50 characters, inclusive.
-The conjoint dateList will contain a single space separated list of dates without leading or trailing spaces.
-Each date in dateList will be in the form "XX/XX" (quotes for clarity), where each X is a digit.
-Each date in dateList will represent a valid date in either US format or European format.
 

Examples

0)
    
{"16/01"}
Returns: "01/16"
The example from the problem statement.
1)
    
{"02/01 08/02 08/02 21/09 06/11"}
Returns: "01/02 02/08 08/02 09/21 11/06"
The first date is either January 2 or February 1.

The second date is either February 8 or August 2.

The third date is either February 8 or August 2.

The fourth date is definitely September 21.

The fifth date is either June 11 or November 06.

There are two ways to interpret these dates in strictly increasing order: "01/02 02/08 08/02 09/21 11/06" and "02/01 02/08 08/02 09/21 11/06". The first variant comes earlier lexicographically.
2)
    
{"08/02 08/02 03/04"}
Returns: ""
3)
    
{"2", "9/02", " 08/", "03 01/08"}
Returns: "02/29 03/08 08/01"
4)
    
{"17/01 05/05 03/07 07/24 23/09 09/30 01/11 11/11"}
Returns: "01/17 05/05 07/03 07/24 09/23 09/30 11/01 11/11"

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10711&pm=7654

Writer:

Andrew_Lazarev

Testers:

PabloGilberto , brett1479 , Yarin , Olexiy , ivan_metelsky

Problem categories:

Simulation, String Parsing