#P2010. Palindromic Dates
Palindromic Dates
Palindromic Dates
In daily life, a unique date can be determined by its year, month, and day. In this problem, a date is represented by an 8-digit number in the format YYYYMMDD, where the first 4 digits represent the year, the next 2 digits represent the month, and the last 2 digits represent the day. Note that each real date has a unique 8-digit representation, and two different dates will have different representations.
A date is defined as palindromic if and only if its 8-digit representation is a palindrome. In other words, if we denote the representation as a sequence of digits \(d_1 d_2 d_3 d_4 d_5 d_6 d_7 d_8\), the date is palindromic if:
[ \forall, i,(1 \le i \le 8),\quad d_i = d_{9-i} ]
For example:
- The date November 19, 2016 is represented as
20161119
and is not a palindrome. - The date January 2, 2010 is represented as
20100102
and is a palindrome. - The date October 2, 2010 is represented as
20101002
and is not a palindrome.
It is known that the number of days in each month is as follows:
- Months 1, 3, 5, 7, 8, 10, 12 have 31 days.
- Months 4, 6, 9, 11 have 30 days.
- February has 28 days in a common year and 29 days in a leap year.
A year is a leap year if and only if it satisfies one of the following conditions:
[ \text{(1) } (\text{year} \bmod 4 = 0) \text{ and } (\text{year} \bmod 100 \neq 0) \quad \text{or} \quad \text{(2) } (\text{year} \bmod 400 = 0). ]
Your task is: Given two dates (in the 8-digit format) that represent the start and end dates (inclusive), determine how many real dates within this range are palindromic.
Note: A palindromic 8-digit number in the format YYYYMMDD
must satisfy that for the year string Y1Y2Y3Y4
, the month is formed as Y4Y3
and the day is formed as Y2Y1
.
inputFormat
The input consists of a single line containing two 8-digit numbers separated by a space. The first number is the start date and the second number is the end date. Both dates are in the format YYYYMMDD
.
You can assume that the start date is not later than the end date and that both dates represent valid calendar dates.
outputFormat
Output a single integer representing the number of palindromic dates between the given start and end dates (inclusive).
sample
20100101 20101231
1