文章
1
粉丝
213
获赞
3
访问
6.3k
非常简洁非常妙
让y1m1d1的日期逐渐靠近目标日期
#include<stdio.h>
int main()
{
int month[13]= {31,28,31,30,31,30,31,31,30,31,30,31};
int cnt=0;
int y1,y2,m1,m2,d1,d2;
scanf("%4d%2d%2d",&y1,&m1,&d1);
scanf("%4d%2d%2d",&y2,&m2,&d2);
while(1)
{
while(y2>=y1)
{
if(y1%4==0&&y1%100!=0||y1%400==0)
{
month[1]=29;
}
while(m1<=12)
{
while(d1<=month[m1-1])
{
if(y1==y2&&m1==m2&&d1==d2)
{
goto PRINT;
break;
}
cnt++;
d1++;
}
d1=1;
m1++;
}
m1=1;
y1++;
}
}
PRINT:
printf("%d\n",cnt+1);
return 0;
}
登录后发布评论
这个解法好啊,非常简洁