/*
* Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 作 者:马广明
* 完成日期:2014 年 3 月 9 日
* 版 本 号:v1.0
* 问题描述: 生日差几天
*/
#include <iostream>
using namespace std;
struct Date
{
int year;
int month;
int day;
}date;
int ta(Date);
int main()
{
int t,t1,t2;
cout<<"第一个人的出生日期:";
cin>>date.year>>date.month>>date.day;
t1=ta(date);
cout<<"第二个人的出生日期:";
cin>>date.year>>date.month>>date.day;
t2=ta(date);
t=t2-t1;
if(t<0)
{
t=-t;
}
cout<<"两人生日相差"<<t<<"天."<<endl;
}
int ta(Date date)
{
int m=0,y=0,x=0,d;
for(int i=1900; i<date.year; i++)
{
y+=365;
if(i%400==0||(i%4==0&&i%100!=0))
{
y++;
}
}
for(int j=0; j<date.month; ++j)
{
if(j==2)
{
if(date.year%400==0||(date.year%4==0&&date.year%100!=0))
{
x=29;
}
else
{
x=28;
}
}
else if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
x=31;
else if(j==4||j==6||j==9||j==11)
x=30;
else if(j==0)
x=date.day;
m+=x;
}
d=y+m;
return d;
}
生日相差几天
最新推荐文章于 2021-03-26 04:41:51 发布