DateFormat
SRM 354 · 2007-06-14 · by Andrew_Lazarev
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
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.
{"16/01"}
Returns: "01/16"
The example from the problem statement.
{"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.
{"08/02 08/02 03/04"}
Returns: ""
{"2", "9/02", " 08/", "03 01/08"}
Returns: "02/29 03/08 08/01"
{"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"
Submissions are judged against all 193 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class DateFormat with a public method string fromEuropeanToUs(vector<string> dateList) · 193 test cases · 2 s / 256 MB per case