P2010 [NOIP 2016 Junior] Palindromic Date
Background
NOIP 2016 Junior T2.
Description
In daily life, a unique date can be specified by the three components: year, month, and day.
Niuniu habitually uses an 8-digit number to represent a date, where the first 4 digits denote the year, the next 2 digits denote the month, and the last 2 digits denote the day. Clearly, a date has only one representation, and two different dates do not share the same representation.
Niuniu considers a date to be palindromic if and only if the 8-digit number representing this date is a palindrome. Now Niuniu wants to know: between the two dates he specifies (including both endpoints), how many real dates are palindromic.
An 8-digit number is palindromic if and only if, for all $i$ ($1 \le i \le 8$), the $i$-th digit from the left is the same as the $(9 - i)$-th digit (that is, the $i$-th digit from the right).
For example:
- For November 19, 2016, represented by the 8-digit number $20161119$, it is not palindromic.
- For January 2, 2010, represented by the 8-digit number $20100102$, it is palindromic.
- For October 2, 2010, represented by the 8-digit number $20101002$, it is not palindromic.
Each year has 12 months:
Among them, months $1, 3, 5, 7, 8, 10, 12$ each have $31$ days; months $4, 6, 9, 11$ each have $30$ days; and for February, there are $29$ days in a leap year and $28$ days in a common year.
A year is a leap year if and only if it satisfies one of the following:
1. The year is a multiple of $4$ but not a multiple of $100$;
2. The year is a multiple of $400$.
For example:
- The following years are leap years: $2000, 2012, 2016$.
- The following years are common years: $1900, 2011, 2014$.
Input Format
Two lines, each containing an 8-digit number.
The first line is the start date specified by Niuniu.
The second line is the end date specified by Niuniu.
It is guaranteed that $\mathit{date}_1$ and $\mathit{date}_2$ are real dates, the year part always has 4 digits with a nonzero first digit, and $\mathit{date}_1$ is not later than $\mathit{date}_2$.
Output Format
Output a single integer, representing how many dates between $\mathit{date}_1$ and $\mathit{date}_2$ (inclusive) are palindromic.
Explanation/Hint
Sample Explanation:
- For sample 1, the valid date is $20111102$.
- For sample 2, the valid dates are $20011002$ and $20100102$.
Subtasks:
- For $60\%$ of the testdata, $\mathit{date}_1 = \mathit{date}_2$.
Translated by ChatGPT 5