#11668: 請教各位高手~~~


ianlu0415 (acelectric)

學校 : 國立陽明高級中學
編號 : 56839
來源 : [120.101.34.83]
最後登入時間 :
2018-05-30 13:00:41
a263. 日期差幾天 -- 板橋高中練習題 | From: [220.132.177.244] | 發表日期 : 2017-01-10 20:36

第 1 測資點(100%): WA (line:1)
答案不正確

您的答案為: 226879
正確答案為: 227031

#include <stdio.h>

int month_days(int Y,int M){
switch(M){
case 1: case 3: case 5: case 7:
case 8: case 10: case 12:
return 31;
break;
case 4: case 6: case 9: case 11:
return 30;
break;
case 2:
if(Y % 400 == 0 || (Y % 4 == 0 && Y % 100 != 0)){
return 29;
}else{
return 28;
}
break;
default :
return -1;
break;
}
}

int year_days(int y){
if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)){
return 366;
}else{
return 365;
}
}
int day_sum(int Y,int M,int D){
int i,sum;
for(i = 1,sum=D;i < M;i++){
sum += month_days(Y,i);
}
return sum;
}

int main(void){
int y_1,m_1,d_1;
int y_2,m_2,d_2;
int temp;
int i,ans;
while(scanf("%d%d%d%d%d%d",&y_1,&m_1,&d_1,&y_2,&m_2,&d_2) != EOF){
int sum_1 = 0,sum_2 = 0;
if(y_2 > y_1){
temp = y_2;
y_2 = y_1;
y_1 = temp;
temp = m_2;
m_2 = m_1;
m_1 = temp;
temp = d_2;
d_2 = d_1;
d_1 = temp;
}
sum_2 = day_sum(y_2,m_2,d_2);
for(i = y_1;y_1 > y_2;--y_1){
sum_1 += year_days(i);
}
sum_1 += day_sum(y_1,m_1,d_1);
if(sum_1 >= sum_2){
ans = sum_1 - sum_2;
}else{
ans = sum_2 - sum_1;
}
printf("%d\n",ans);
}
return 0;
}

 
ZeroJudge Forum