/*
* 程序的版权和版本声明部分
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: fibnacci.cpp
* 作 者:高古尊
* 完成日期:2014年2月27日
* 版本号: v1.0
*
* 输入描述:
* 问题描述:定义一个结构体变量(包括年、月、日),要求输入年、月、日,
计算输出该日是该年的第几天
* 程序输出:
* 问题分析:
*/
#include <iostream>
using namespace std;
struct Date
{
int year;
int moth;
int day;
int shi;
int fen;
int miao;
};
int main()
{
int moth2;
Date date,date2;
cout<<"请输入年 月 日 时 分 秒:";
cin>>date.year>>date.moth>>date.day>>date.shi>>date.fen>>date.miao;
int days;
if((date.year%4==0&&date.year%100!=0)||(date.year%400==0))
moth2=29;
else
moth2=28;
if(date.moth==3||date.moth==5||date.moth==7)
{
days=(date.moth-1)*30+date.day-(30-moth2)+(date.moth-1)/2;
}
else
{
if(date.moth==2||date.moth==4||date.moth==6)
{
days=(date.moth-1)*30+date.day-(30-moth2)+date.moth/2;
}
else
{
if(date.moth==8||date.moth==10||date.moth==12)
{
days=4*31+2*30+moth2+(date.moth-8)*31-(date.moth-8)/2+date.day;
}
else
{
if(date.moth==9||date.moth==11)
{
days=4*31+2*30+moth2+31+(date.moth-8)*30+(date.moth-9)/2+date.day;
}
else
{
if(date.moth==1)
{
days=date.day;
}
else
{
days=31+date.day;
}
}
}
}
}
cout<<"是这一年的第"<<days<<"天."<<endl;
cout<<"是这一天的第"<<(date.shi*60*60+date.fen*60+date.miao)<<"秒。"<<endl;
cout<<"是这一年的第"<<(days*24*60*60+date.shi*60*60+date.fen*60+date.miao)<<"秒。"<<endl;
date2=date;
int d,m=0,n=0,t=0;
cin>>d;
date.moth=1;
while(n!=d+days)
{
m++;
n++;
t++;
if((date.year%4==0&&date.year%100!=0)||(date.year%400==0))
{
if(t==366)
{
t=0;
date.year++;
}
if(date.moth==1||date.moth+1==3||date.moth+1==5||date.moth+1==7||date.moth+1==8||date.moth+1==10||date.moth+1==12)
{
if(m==31)
{
m=0;
date.moth++;
}
}
else
{
if(date.moth+1==2)
{
if(m==29)
{
m=0;
date.moth++;
}
}
else
{
if(m==31)
{
m=0;
date.moth++;
}
}
}
}
else
{
if(t==365)
{
t=0;
date.year++;
}
if(date.moth+1==1||date.moth+1==3||date.moth+1==5||date.moth+1==7||date.moth+1==8||date.moth+1==10||date.moth+1==12)
{
if(m==31)
{
m=0;
date.moth++;
}
}
else
{
if(date.moth+1==2)
{
if(m==28)
{
m=0;
date.moth++;
}
}
else
{
if(m==31)
{
m=0;
date.moth++;
}
}
}
}
}
cout<<"天后是:"<<date.year<<"年"<<date.moth<<"月"<<date.day<<"日"<<endl;
date=date2;
int l;
m=0,n=0,t=0;
cin>>l;
d=l/(24*60*60);
date.shi=(l%(24*60*60))/360;
date.fen=((l%(24*60*60))%360)/60;
date.miao=((l%(24*60*60))%360)%60;
date.moth=1;
while(n!=d+days)
{
m++;
n++;
t++;
if((date.year%4==0&&date.year%100!=0)||(date.year%400==0))
{
if(t==366)
{
t=0;
date.year++;
}
if(date.moth==1||date.moth==3||date.moth==5||date.moth==7||date.moth==8||date.moth==10||date.moth==12)
{
if(m==31)
{
m=0;
date.moth++;
}
}
else
{
if(date.moth==2)
{
if(m==29)
{
m=0;
date.moth++;
}
}
else
{
if(m==31)
{
m=0;
date.moth++;
}
}
}
}
else
{
if(t==365)
{
t=0;
date.year++;
}
if(date.moth==1||date.moth==3||date.moth==5||date.moth==7||date.moth==8||date.moth==10||date.moth==12)
{
if(m==31)
{
m=0;
date.moth++;
}
}
else
{
if(date.moth==2)
{
if(m==28)
{
m=0;
date.moth++;
}
}
else
{
if(m==31)
{
m=0;
date.moth++;
}
}
}
}
}
cout<<"天后是:"<<date.year<<"年"<<date.moth<<"月"<<date.day<<"日"<<date.shi<<"时"<<date.fen<<"分"<<date.miao<<"秒"<<endl;
return 0;
}