问题3453--Palindromic Dates

3453: Palindromic Dates

[命题人 : ]
时间限制 : 30.000 sec  内存限制 : 64 MB

题目描述

A date is said to be palindromic if, when written in the form “YearMMDD”, the result is a palindrome (a number that has the same value regardless if we read it left-to-right or right-to-left). For example, the date “January 1st, 1” is palindromic since it would be written as “10101”; “December 1st, 1021” is palindromic too, since it would be written as “10211201”. Given a date, you are required to find the next valid date (in chronological order) that is palindromic (according to the definition of “palindromic date” that was given in the previous paragraph). For the purpose of this problem, a date is considered valid if the year is between 1 and 2147483647, the month is between 1 and 12, the day is at least 1 and:  for months 1,3,5,7,8,10,12 – the day is not greater than 31  for months 4,6,9,11 – the day is not greater than 30  for month 2, the day is not greater than 29, and can be 29 only during leap years. A year is considered “leap year” if it is divisible by 400, or is divisible by 4 but not by 100.

输入

The input file contains one date per line: thee numbers separated by the character ‘/’, representing (in order) the day, month and year. For example, July 4th 2011 would be written as “04/07/2011” (or 4/07/2011, or 4/7/2011). The last line in the input file is empty.

输出

The output file shall contain the next valid palindromic date for each date in the input file, one date per line. The date format in the output file is DD/MM/Year – i.e. the separator character is '/', the year’s first digit must never be 0, and you must always use two digits for day and month (use 01 instead of 1, 02 instead of 2 etc.). It is guaranteed that all input dates are valid, and that for all input dates there is a “next valid palindromic date”.

样例输入 Copy

1/1/1
12/11/1
01/06/138048967

样例输出 Copy

01/02/1
11/12/1
31/08/138048984

来源/分类