import java.util.Scanner; public class Main { static String[] month={ "January","February","March","April","May","June","July", "August","September","October","November","December" }; public static void main(String[] args){ Scanner s = new Scanner(System.in); int a = s.nextInt(); //要加循环读入数据,每读入一次调用一次find229 int sum[] = new int[a]; String[] date1 = new String[3]; String[] date2 = new String[3]; for(int i = 0;i<a;i++){ for(int j =0;j<3;j++){ date1[j] = s.next(); } for(int j =0;j<3;j++){ date2[j] = s.next(); } sum[i] = find229(date1,date2); } for(int i = 0;i<a;i++){ System.out.println("Case #"+(i+1)+": "+sum[i]); } s.close(); } public static int find229(String[] date1,String[] date2){ int year1 = Integer.valueOf(date1[2]); int year2 = Integer.valueOf(date2[2]); int day2 = Integer.valueOf(date2[1].split(",")[0]); int result = 0; for(int i = ((year1-1)/4+1)*4;i<=(year2/4)*4;i = i+4){//保证每个年份能被4整除 if(i%400 == 0){ //从某一个能被400整除的数开始,每400个数里面有96个能被4整除但不能被100整除的数,有一个能被400整除的数,算上尾,不算头 //比如400~800,则是从401~800有一个能被400整除的数,有96个能被4整除不能被100整除的数 result++; result += (year2/400-i/400)*97; //小于ed.year的最大的能被400整除的数 i = (year2/400)*400; }else if(i%100!=0){//不能被400整除时 result++; } } //考虑起止年份 if(year1%400==0||(year1%4==0&&year1%100!=0)){ if(!(month[0].equals(date1[0])||month[1].equals(date1[0]))){ result--; } } if(year2%400==0||(year2%4==0&&year2%100!=0)){ if(month[0].equals(date2[0])){ result--; }else if(month[1].equals(date2[0])&&day2<29){ result--; } } return result; } }
时间: 2024-11-04 14:23:41