AcWing 466. 回文日期(java)
原题链接
简单
作者:
文思涌
,
2021-02-24 13:20:27
,
所有人可见
,
阅读 383
private static int[] days= {0,31,28,31,30,31,30,31,31,30,31,30,31};
public static boolean check_valid(int date) {
int year=date/10000;
int month=date/100%100;
int day=date%100;
if(month<1||month>12)return false;
if(day<1||month!=2&&day>days[month])return false;
if(month==2) {
int leap=0;
if(year%100!=0&&year%4==0||year%400==0) {
leap=1;
}
if(day>28+leap)return false;
}
return true;
}
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int date1=scanner.nextInt();
int date2=scanner.nextInt();
int res=0;
for(int i=1000;i<10000;i++) {
int date=i;
int x=i;
for(int j=0;j<4;j++) {
date=date*10+x%10;
x/=10;
}
if(date1<=date&&date<=date2&&check_valid(date))res++;
}
System.out.println(res);
}