Goldman SachsOA #30
Preprocess Dates
估计简单评测数据准备中,可先阅读题面
考点(AI 标注)字符串
On a web form, users are asked to enter dates which come in as strings. Before storing them to the database,
they need to be converted to a standard safe format. Write a function to convert the dates as described.
Given a date string in the format Day Month Year, where:
-
- Day is a string in the form "1st", "2nd", "3rd", "21st", "22nd", "23rd", "31st" and all other are the number + "th", eg: "4th" or "12th".
- Month is the first three letters of the English language months, like "jan" for January through "Dec" for December.
- Year is 4 digits ranging from 1900 to 2100.
Convert the date string
"Day Month Year"to the date string"YYYY-MM-DD"in the format"4 digit year - 2 digit month - 2 digit day". Function Description Complete the functionpreprocessDate.preprocessDatehas the following parameter(s): string dates[n]: an array of date strings in the format Day Month Year Returnsstring[n]: array of converted date strings
Constraints
- the values of Day, Month, Year are restricted to the value ranges specified above.
- The given
Example 1
Input:
dates = ["1st Mar 1974", "22nd Jan 2013", "7th Apr 1904"]
Output:
["1974-03-01", "2013-01-22", "1904-04-07"]
Explanation:
- 1st Mar 1974 is converted to 1974-03-01.
- 22nd Jan 2013 is converted to 2013-01-22.
- 7th Apr 1904 is converted to 1904-04-07.