zoukankan      html  css  js  c++  java
  • YTU 2911: 我想放假

    2911: 我想放假

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 124  解决: 46

    题目描述

    小明的弟弟上小学了,每次刚入学就想知道什么时候放假,但是每学期开学的日子和每学期的有效天数都不一样,请你编程帮他计算放假日期。

    本题只需要提交填空部分

    #include <iostream>
    using namespace std;
    class Date
    {
    public:
        void input(int y,int m,int d);
        friend Date operator+(Date &c,int &day);
        void display();
    private:
        int year;
        int month;
        int day;
    };

    void Date::input(int y,int m,int d)
    {
        year=y;
        month=m;
        day=d;
    }
    Date operator+(Date &c,int &day)
    {
        /*********************/

                  填空部分

        /*********************/
    }

    void Date::display()
    {
        cout<<year<<"/"<<month<<"/"<<day<<endl;
    }
    int main()
    {
        Date date1,date2;
        int y,m,d;
        int day;
        cin>>y>>m>>d;
        date1.input(y,m,d);
        cin>>day;
        date2=date1+day;
        date2.display();
        return 0;
    }

    输入

    第一行输入开学的年月日,以空格隔开;第二行输入本学期的有效天数

    输出

    输出计算后得到的放假日期,格式为年/月/日。

    样例输入

    2008 2 29
    140

    样例输出

    2008/7/18
    

    im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......可怜

    #include <iostream>
    using namespace std;
    class Date
    {
    public:
        void input(int y,int m,int d);
        friend Date operator+(Date &c,int &day);
        void display();
    private:
        int year;
        int month;
        int day;
    };
    void Date::input(int y,int m,int d)
    {
        year=y;
        month=m;
        day=d;
    }
    Date operator+(Date &c,int &day)
    {
        Date d;
        int year,month,days;
        year=c.year;
        month=c.month;
        days=c.day;
        int i;
        for(i=1; i<=day; i++)
        {
            days=days+1;
            if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
            {
                if(days==32)
                {
                    month=month+1;
                    days=1;
                }
                if(month==13)
                {
                    year=year+1;
                    month=1;
                }
            }
            if(month==2)
            {
                if(((year%4==0&&year%100!=0)||year%400==0))
                {
                    if(days==30)
                    {
                        days=1;
                        month=month+1;
                    }
                }
                else
                {
                    if(days==29)
                    {
                        days=1;
                        month=month+1;
                    }
                }
            }
            if(month==4||month==6||month==9||month==11)
            {
                if(days==31)
                {
                    month=month+1;
                    days=1;
    
                }
                if(month==13)
                {
                    year=year+1;
                    month=1;
                }
            }
        }
        d.year=year;
        d.month=month;
        d.day=days;
        return d;
    }
    
    void Date::display()
    {
        cout<<year<<"/"<<month<<"/"<<day<<endl;
    }
    int main()
    {
        Date date1,date2;
        int y,m,d;
        int day;
        cin>>y>>m>>d;
        date1.input(y,m,d);
        cin>>day;
        date2=date1+day;
        date2.display();
        return 0;
    }
    


  • 相关阅读:
    使用Azure Rest API获得Access Token介绍
    Azure Service Fabric应用程序日志记录与展现
    Azure Web App创建Python应用
    AzureWeb App如何做私有仓储的部署
    Python web在IIS上发布方法和原理
    [转载]DriverStore文件夹特别大,能删除吗?
    Azure Web APP中Local Git 如何部署分支
    Azure Web 应用如何修改 IIS 配置
    文件上传绕过
    windows下通过配置服务器安全策略指定IP地址远程访问服务器的设置方法
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989661.html
Copyright © 2011-2022 走看看