日期相差的天数计算201307311924.txt
Posted 夏子藤
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了日期相差的天数计算201307311924.txt相关的知识,希望对你有一定的参考价值。
输入
1978 10 1 1978 10 1
1978 10 1 1978 10 2
1978 10 2 1978 10 1
2001 1 1 2000 1 1
2000 1 1 2002 1 1
输出
0
1
1
366
731
#include "stdio.h"
int main()
{
int b[2]={365,366};
int a[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,
0,31,29,31,30,31,30,31,31,30,31,30,31};
int year1,month1,day1,year2,month2,day2;
int s1,s2,i,s,t,j;
scanf("%d%d%d%d%d%d",&year1,&month1,&day1,&year2,&month2,&day2);
if(year1==year2)//同年份的情况
{
if(month1>month2)
{t=month1;month1=month2;month2=t;}
{t=day1;day1=day2;day2=t;}
if(month1==month2&&day1>day2)
{t=day1;day1=day2;day2=t;}
s1=s2=0;
j=(year1%400==0||(year1%4==0&&year1%100!=0));
for(i=0;i<month1;i++)
{
s1=s1+a[j][i];
}
s1=s1+day1;
for(i=0;i<month2;i++)
{
s2=s2+a[j][i];
}
s2=s2+day2;
if(s1>s2)
{t=s1;s1=s2;s2=t;}
s=s2-s1;
//printf("%d\n",s);
}
if(year1>year2)//不同年份的情况
{
{t=year1;year1=year2;year2=t;}
{t=month1;month1=month2;month2=t;}
{t=day1;day1=day2;day2=t;}
}
if(year1<year2)
{
s=s1=s2=0;
j=(year1%400==0||(year1%4==0&&year1%100!=0));
for(i=0;i<month1;i++)
{s1=s1+a[j][i];}
s1=s1+day1;
s1=b[j]-s1;
j=(year2%400==0||(year2%4==0&&year2%100!=0));
for(i=0;i<month2;i++)
{s2=s2+a[j][i];}
s2=s2+day2;
year1+=1;
j=(year1%400==0||(year1%4==0&&year1%100!=0));
for(;year1<year2;)
{
s=s+b[j];
year1+=1;
j=(year1%400==0||(year1%4==0&&year1%100!=0));
}
s=s+s1+s2;
}
printf("%d\n",s);
return 0;
}
以上是关于日期相差的天数计算201307311924.txt的主要内容,如果未能解决你的问题,请参考以下文章