#10861: 這題哪裡寫錯??卡在17行


hointw (oldboy)

學校 : 國立聯合大學
編號 : 57354
來源 : [36.226.198.41]
最後登入時間 :
2016-04-16 08:28:18
a263. 日期差幾天 -- 板橋高中練習題 | From: [118.99.219.9] | 發表日期 : 2016-04-15 17:43

#include<stdio.h>

int main(){
int daysOfMonth[13]={31,31,28,31,30,31,30,31,31,30,31,30,31};
int y0,y1,m0,m1,d0,d1,days,daysInYear0,daysInYear1;
while (scanf("%d%d%d%d%d%d",&y0,&m1,&d0,&y1,&m1,&d1)!=EOF){
if(y0*10000+m0*100+d0>y1*10000+m1*100+d1){
int k;
k=y0,y0=y1,y1=k;
k=m0,m0=m1,m1=k;
k=d0,d0=d1,d1=k;
}
days = 0,daysInYear0=0,daysInYear1=0;
for(;y1==y0;y0++)
days+=y0%4?365:y0%100?366:y0%400?365:366;
daysOfMonth[2]=y0%4?28:y0%100?29:y0%400?28:29;
for (int i=1 ;i<=m0-1,i++)
daysInYear0+=daysOfMonth[i];
for (int i=1 ;i<=m0-1;i++)
daysInYear1+=daysOfMonth[i];
daysInYear0+=d0;
daysInYear1+=d1;
days+=daysInYear1-daysInYear0;
printf("%d\n",days);

//for(;y1!=y0;y0++)
// daysInYear0+=day
}
}

 
#16016: Re:這題哪裡寫錯??卡在17行


10555088@mail.hpsh.tp.edu.tw (3.141592653589793238462)

學校 : 不指定學校
編號 : 70904
來源 : [210.71.78.245]
最後登入時間 :
2020-05-04 15:39:14
a263. 日期差幾天 -- 板橋高中練習題 | From: [223.140.226.131] | 發表日期 : 2018-11-11 15:33

#include

int main(){
int daysOfMonth[13]={31,31,28,31,30,31,30,31,31,30,31,30,31};
int y0,y1,m0,m1,d0,d1,days,daysInYear0,daysInYear1;
while (scanf("%d%d%d%d%d%d",&y0,&m1,&d0,&y1,&m1,&d1)!=EOF){
if(y0*10000+m0*100+d0>y1*10000+m1*100+d1){
int k;
k=y0,y0=y1,y1=k;
k=m0,m0=m1,m1=k;
k=d0,d0=d1,d1=k;
}
days = 0,daysInYear0=0,daysInYear1=0;
for(;y1==y0;y0++)
days+=y0%4?365:y0%100?366:y0%400?365:366;
daysOfMonth[2]=y0%4?28:y0%100?29:y0%400?28:29;
for (int i=1 ;i<=m0-1,i++)
daysInYear0+=daysOfMonth[i];
for (int i=1 ;i<=m0-1;i++)
daysInYear1+=daysOfMonth[i];
daysInYear0+=d0;
daysInYear1+=d1;
days+=daysInYear1-daysInYear0;
printf("%d\n",days);

//for(;y1!=y0;y0++)
// daysInYear0+=day
}
}

scanf那一行寫錯了

m0沒存到,寫了兩個m1

 
ZeroJudge Forum