2024-3-3-466-回文日期.cpp

2024-3-3-466-回文日期.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
const int N = 10010;

int day1,day2,res,days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

bool check(int date)
{int year=date/10000;
int mouth=date%10000/100;
int day=date%100;
if(mouth==0||mouth>12)return false;
if(day==0||mouth!=2&&day>days[mouth]) return false;
int leap=year%100&&year%4==0||year%400==0;//注意闰年判断条件
if(mouth==2){
if(day>28+leap) return false;
}
return true;
}
int main()
{
cin>>day1>>day2;
int rea=0;
for(int i=1000;i<10000;i++)
{
int date=i,x=i;
for(int j=0;j<4;j++)
date=date*10+x%10,x/=10;
if(day1<=date&&day2>=date&&check(date))res++;
}
cout<<res;
return 0;
}