#include <stdio.h>
int main()
{
char a[11];//生日
char b[11];//现在
int i;
int sum=365;
int day=365;
int run_month;
int flag;
printf("请输入你的生日:(如1988-05-20):");
for(i=0;i<10;i++)
{
scanf("%c",&a[i]);
}
a[10]='\0';
printf("%s\n",a);
printf("请输入现在的时期:(如2009-12-07):");
getchar();
for(i=0;i<10;i++)
{
scanf("%c",&b[i]);
}
b[10]='\0';
printf("%s\n",b);
int year_2 = (int)(b[0]-'0')*1000+(int)(b[1]-'0')*100+(int)(b[2]-'0')*10+(int)(b[3]-'0');
int year_1=(int)(a[0]-'0')*1000+(int)(a[1]-'0')*100+(int)(a[2]-'0')*10+(int)(a[3]-'0');
int month_2=(int)(b[5]-'0')*10+(int)(b[6]-'0');
int month_1=(int)(a[5]-'0')*10+(int)(a[6]-'0');
int day_2=(int)(b[8]-'0')*10+(int)(b[9]-'0');
int day_1=(int)(a[8]-'0')*10+(int)(a[9]-'0');
while(year_1<year_2)
{
if(year_1%4==0 && year_1%100!=0)
{
day=366;
run_month = 29;
flag = 3;
}
else if(year_1%400==0)
{
day=366;
run_month = 29;
flag=3;
}
else
{
day=365;
run_month = 28;
flag=4;
}
sum = sum + day;
year_1 = year_1+1;
}
if(year_2%4==0 && year_2%100!=0)
{
run_month = 29;
flag = 1;
}
else if(year_2%400==0)
{
run_month = 29;
flag=1;
}
else
{
run_month = 28;
flag=2;
}
for(i=1;i<month_2;i++)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
{
sum = sum +31;
}
else if(i==2)
{
if(flag==1)
{
sum = sum + 29;
}
else if(flag==2)
{
sum = sum +28;
}
}
else
{
sum = sum +30;
}
}
for(i=1;i<month_1;i++)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)
{
sum = sum -31;
}
else if(i==2)
{
if(flag==3)
{
sum = sum - 29;
}
else if(flag==4)
{
sum = sum -28;
}
}
else
{
sum = sum -30;
}
}
printf("%d\n",sum);
printf("%d\n",year_1);
return 0;
}
|