题目6 日期差值
1 import java.util.Arrays; 2 import java.util.Comparator; 3 import java.util.Scanner; 4 5 public class Main{ 6 public static void main(String[]args){ 7 Date t=new Date(); 8 t.year=0; 9 t.month=1; 10 t.day=1; 11 int count=0; 12 while(t.year!=5001){ 13 buf[t.year][t.month][t.day]=count; 14 t.nextDate(); 15 count++; 16 } 17 18 Scanner in=new Scanner(System.in); 19 while(in.hasNext()){ 20 String day=in.nextLine(); 21 String y=day.substring(0, 4); 22 int y_=Integer.valueOf(y); 23 String m=day.substring(4, 6); 24 int m_=Integer.valueOf(m); 25 String d=day.substring(6, 8); 26 int d_=Integer.valueOf(d); 27 int x1=buf[y_][m_][d_]; 28 day=in.nextLine(); 29 y=day.substring(0, 4); 30 y_=Integer.valueOf(y); 31 m=day.substring(4, 6); 32 m_=Integer.valueOf(m); 33 d=day.substring(6, 8); 34 d_=Integer.valueOf(d); 35 int x2=buf[y_][m_][d_]; 36 System.out.println(Math.abs(x1-x2)+1); 37 } 38 } 39 private static int isYeap(int x){ 40 if(x%4==0&&x%100!=0||x%400==0) return 1; 41 else return 0; 42 } 43 private static int[][]dayOfMonth={ 44 {0,0}, 45 {31,31}, 46 {28,29}, 47 {31,31}, 48 {30,30}, 49 {31,31}, 50 {30,30}, 51 {31,31}, 52 {31,31}, 53 {30,30}, 54 {31,31}, 55 {30,30}, 56 {31,31} 57 }; 58 private static class Date{ 59 int year; 60 int month; 61 int day; 62 void nextDate(){ 63 day++; 64 if(day>dayOfMonth[month][isYeap(year)]){ 65 day=1; 66 month++; 67 } 68 if(month>12){ 69 month=1; 70 year++; 71 } 72 } 73 } 74 private static int[][][]buf=new int[5001][13][32]; 75 }