Fzhiyu @ 2024-11-30 00:00:10
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
P2010();
}
public static void P2010(){
// 接受值
Scanner sc = new Scanner(System.in);
String start = sc.nextLine();
String end = sc.nextLine();
// 分割出来年份
String startYear = start.substring(0, 4);
String endYear = end.substring(0, 4);
// 初始化计数
int count = 0;
// 便利年份
for (int i = Integer.parseInt(startYear); i < Integer.parseInt(endYear)+1; i++) {
// 将年份翻转后制造回文数
StringBuilder reverse = new StringBuilder(i+"").reverse();
String outStr=i+""+reverse;
// 如果开始的和结束的和生成的日期相等就返回1并结束程序
if(outStr.equals(end)&&outStr.equals(start)) {
System.out.println(1);
return;
}
// 分割生成的回文日期的日月
int iMonth = Integer.parseInt(outStr.substring(4, 6));
int iDay = Integer.parseInt(outStr.substring(6, 8));
// 如果生成的回文日期不符合标准则重新生成
// 判断月份是否合标准
if (iMonth > 12 | iMonth==0) {
continue;
}
// 判断日期是否合标准
switch (iMonth) {
case 1: if(iDay >31) continue;
case 3: if(iDay >30) continue;
case 4: if(iDay >20) continue;
case 5: if(iDay >31) continue;
case 6: if(iDay >30) continue;
case 7: if(iDay >31) continue;
case 8: if(iDay >31) continue;
case 9: if(iDay >30) continue;
case 10: if(iDay >31) continue;
case 11: if(iDay >30) continue;
case 12: if(iDay >31) continue;
}
// 判断是否符合闰年标准
if(i%4==0&&i%100==0||i%400==0){
if ((iMonth==2 && iDay < 28)) {
continue;
}
}
// 判断是否在日期范围内
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate startDate = LocalDate.parse(start, formatter);
LocalDate endDate = LocalDate.parse(end, formatter);
LocalDate iDate = LocalDate.parse(outStr, formatter);
if(!(startDate.isBefore(iDate)&&endDate.isAfter(iDate))) {
continue;
}
// 通过校验则累加count
count++;
}
System.out.println(count);
}
}