日期结构体

来源:互联网 发布:手机4g网络怎么加速 编辑:程序博客网 时间:2024/06/08 06:15
/** 程序的版权和版本声明部分* 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 main(){    int moth2;    Date date;    cout<<"input yeaer,month,day:";    cin>>date.year>>date.moth>>date.day;    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<<date.moth<<"月"<<date.day<<"日是"<<date.year<<"年的第"<<        days<<"天."<<endl;    return 0;}

 

想法简单,不一定好写代码

 


 

0 0
原创粉丝点击