Title Description
In daily life, by year, month, day of the three elements of a date can be expressed uniquely determined.
Taurus practice of using 8 represents an 8-digit date, of which the first 4 four years on behalf of, the next 2 two for the month and the last 2 2 represents the date. Obviously: there is only one representation of a date, but two different representations of the same date will not.
Taurus believes that a date is a palindrome if and only if this represents the 8-digit date is a palindrome. Now, Taurus want to know: between two dates designated by him contains both the date itself), how many are real date is a palindrome.
A . 8 8 palindromic number is, if and only if for all i (. 1 \ i Le \ Le. 8) i ( . 1 ≤ i ≤ . 8 ) from left to right in the i-th digit and the 9-i . 9 - I digits (i.e., from right to left on the number of I I numbers) are the same.
E.g:
• For November 19, 2016, with 8 8 Digital 20,161,119 2 0 1 6 1 1 1 9 shows, it is not a palindrome.
• For the January 2, 2010, with 8 8 Digital 20,100,102 2 0 1 0 0 1 0 2 indicates, it is a palindrome.
• For the October 2, 2010, with 8 8 Digital 20,101,002 2 0 1 0 1 0 0 2 indicates, it is not a palindrome.
Each year there are 12 1 2 Month:
Wherein 1,3,5,7,8,10,12 1 , 3 , 5 , 7 , 8 , 1 0 , 1 have a month of February 31 is 3 1 day; 4,6,9,11 4 , 6 , 9 , 1 1 of each month 30 . 3 0 days; for 2 February, there is a leap year. 29 2 9 days, average year when 28 2 8 days.
Year is a leap year if and only if it satisfies the following two conditions one kind which:
1. The year is 4 integer multiple of 4, but not 100 . 1 0 integer multiple of 0;
2. The year is 400 . 4 0 integral multiple of 0.
E.g:
• the following year is a leap year: 2000,2012,2016 2 0 0 0 , 2 0 1 2 , 2 0 1 6
• the following year is leap year: 1900,2011,2014 1 9 0 0 , 2 0 1 1 , 2 0 1 4
Input Format
Two rows, each row comprising a . 8 8 digits.
The first line indicates start date specified beef.
The second line represents the Taurus specified termination date.
Ensure DATE \ _i D A T E _ date exists and i are real, and some part of the year . 4 4 digits and the first digit is not 0 0
Ensure DATE. 1 D A T E . 1 - no later than scheduled DATE 2 D A T E 2.
Output Format
An integer representing the date1 D A T E . 1 and DATE2 D A T E between the two, the number of dates is palindromic.
Sample input and output
1 20110101 2 20111231
1 20000101 2 20101231
Description / Tips
[Sample Description]
For the sample 1, qualifying date is 20,111,102 .
For sample 2, the qualifying date is 20,011,002 and 20,100,102 .
【Subtasks】
For . 6 0 % of the data satisfies date1 DATE2 = D A T E . 1 = D A T E 2.
answer
-
analysis
Ideas: first palindromic structure, specific enumeration is the first year, then construction, such as enumeration 2016, the date of construction is 20,166,102, guaranteed to be a palindrome. And then determine whether this date science (ah, science you know)
Time: O (n), n representative of the number of years between the two date range.
-
Code
1 #include<iostream> 2 #include<cstdio> 3 #include<string> 4 #include<map> 5 #include<set> 6 #include<queue> 7 #include<vector> 8 using namespace std; 9 int i,j,n,m,a,b,c,sum,ans; 10 int s[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; 11 int main() 12 { 13 scanf("%d%d",&n,&m); 14 for(i=1;i<=12;i++) 15 { 16 for(j=1;j<=s[i];j++) 17 { 18 c=(j%10)*1000+(j/10)*100+(i%10)*10+(i/10); 19 sum=c*10000+i*100+j; 20 if (sum<n||sum>m) 21 continue; 22 ans++; 23 } 24 } 25 printf("%d",ans); 26 return 0; 27 }