


You are given a string ‘S’ representing a date in the “Day Month Year” format, where:
1. Day is represented as {"1st", "2nd", "3rd", "4th",”5th”, ...,”29th”, "30th", "31st"}.
2. Month is represented as {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}.
3. Year is represented as {2020,2021 etc}
Your task is to convert the given date into “YYYY-MM-DD” format, where:
1. YYYY is a 4 digit year.
2. MM is a 2 digit month.
3. DD is a 2 digit day.
Note:
1. The given dates are guaranteed to be valid.
2. If you can’t represent a month in 2 digits then append 0 in front of the month. Eg: if the month is Jan, represent it as 01 and not as 1 in the answer.
3. If you can’t represent a day in 2 digits then append 0 in front of the day. Eg: if the day is 5, represent it as 05 and not as 5 in the answer.
The first line of the input contains an integer ‘T’ denoting the number of test cases.
The first and the only line of each test case contains one string ‘S’, as described in the problem statement.
Output Format:
For each test case, print a single line containing a single string representing the date in “YYYY-MM-DD” format.
The output of every test case will be printed in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10 ^ 4
Day belongs in the set {"1st", "2nd", "3rd", "4th",”5th”, ...,”29th”, "30th", "31st"}.
Month belongs in the set {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}.
1000 <= Year <= 2021
Time Limit: 1 second.
1
27th Apr 1998
1998-04-27
“27th Apr 1998” will be converted to “1998-04-27” in “YYYY-MM-DD” format.
Handle the conversions of day, month, and year separately.
In this brute force approach, We will keep a map (say ‘MONTHS’) that will map the month given in words to digit, Eg: Apr to 4 and Jan to 1.
Now we will parse the date from left to right and extract the DAY, MONTH and YEAR from the input and finally return YEAR-MONTHS[MONTH]-DAY as the output.
O(1).
Since the size of the given string is very small hence we can consider the time complexity to be O(1).
O(1).
Since we are using constant extra space the space complexity is O(1).