看起來很攏長
public class hiii {
public static int tofix2(int years2, int month2, int days2) {
int sum=0;
int md[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(years2%4==0 && years2%100!=0 || years2%400==0){ //閏年
md[1]=29;
for(int i=0;i<12;i++){
if(i==(month2-1)){
sum += days2; //366-已過天數
break;
}else{
sum+=md[i];
}
}
sum = 366 - sum;
}else{ //平年
for(int i=0;i<12;i++){
if(i==(month2-1)){
sum += days2; //365-已過天數
break;
}else{
sum+=md[i];
}
}
sum = 365 - sum;
}
return sum;
}
public static int tofix(int years ,int month ,int days) {
int sum=0;
int md[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(years%4==0 && years%100!=0 || years%400==0){ //閏年
md[1]=29;
for(int i=0;i<12;i++){
if(i==(month-1)){
sum += days; //算已過天數
break;
}else{
sum+=md[i];
}
}
}else{ //平年
for(int i=0;i<12;i++){
if(i==(month-1)){
sum += days; //算已過天數
break;
}else{
sum+=md[i];
}
}
}
return sum;
}
public static void main(String[] args) throws IOException{
Scanner scanner = new Scanner(System.in);
int years,month,days,
years2,month2,days2;
while(scanner.hasNext()){
years = scanner.nextInt();
month = scanner.nextInt();
days = scanner.nextInt();
years2 = scanner.nextInt();
month2 = scanner.nextInt();
days2 = scanner.nextInt();
int a=0,b=0,yr=0;
//比大小
if((years > years2)){
for(int i=years2+1;i<years;i++){
if(i%4==0 && i%100!=0 || i%400==0){ //閏年
yr+=366;
}else{
yr+=365;
}
}
a = tofix(years,month,days);
b = tofix2(years2,month2,days2);
System.out.println(a+b+yr);
}else if((years2 > years)){
for(int i=years+1;i<years2;i++){
if(i%4==0 && i%100!=0 || i%400==0){ //閏年
yr+=366;
}else{
yr+=365;
}
}
a = tofix(years2,month2,days2);
b = tofix2(years,month,days);
System.out.println(a+b+yr);
}else if(years == years2){
a = tofix(years,month,days);
b = tofix(years2,month2,days2);
System.out.println(Math.abs(a-b));
}
}
}//main
}