3 条题解

  • 0
    @ 2021-03-26 20:21:43
    #include<iostream>
    using namespace std;
    const int N=13;
    bool isleap(int n)
    {
        if(n%4==0&&n%100!=0||n%400==0) return true;
        else return false;
    }
    int main()
    {
        int year,month,day;cin>>year>>month>>day;
        int a[N]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        if(isleap(year)==true) a[2]=29;
        int x;cin>>x;
        while(x!=0)
        {
            day++;
            if(day>a[month]){
                day=1;
                month++;
            }
            if(month>12){
                month=1;
                year++;
                if(isleap(year)==true) a[2]=29;
                else a[2]=28;
            }
            x--; 
        }
        cout<<year<<" "<<month<<" "<<day;
        return 0;
    }
    
  • 0
    @ 2019-03-31 13:22:27
    #include <iostream>
    using namespace std;
    class Date
    {
        int year;
        int month;
        int day;
    public:
        void init(int y, int m, int d)
        {
            year = y;
            month = m;
            day = d;
        }
        int isLeapYear()
        {
            if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
                return 1;
            else
                return 0;
        }
        void add(int num)
        {
            int Month[13] = { 0,31,28 + isLeapYear(),31,30,31,30,31,31,30,31,30,31 };
            day += num;
            while (day > Month[month])
            {
                day -= Month[month];
                month++;
                if (month > 12)
                {
                    month -= 12;
                    year++;
                    Month[2] = 28 + isLeapYear();
                }
            }
        }
        void print()
        {
            cout << year << " " << month << " " << day;
        }
    };
    int main()
    {
        int y, mon, d;
        cin >> y >> mon >> d;
        int num;
        cin >> num;
        Date date;
        date.init(y, mon, d);
        date.add(num);
        date.print();
        return 0;
    }
    
  • -3
    @ 2021-01-29 14:47:14
    #include<iostream>
    using namespace std;
    int main()
    {
        int month_day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        int year,month,day;
        int mum;
        cin>>year>>month>>day>>mum;
        if((year%4==0&&year%100!=0)||(year%400==0))
            month_day[2]=29;
        for(int i=1;i<=mum;i++)
        {
            day++;
            if(day>month_day[month])
            {
                day=1;
                month++;
            }
            if(month>12)
            {
                month=1;
                year++;
                if((year%4==0&&year%100!=0)||(year%400==0))
                    month_day[2]=29;
                else
                    month_day[2]=28;
                
            }
        }
        cout<<year<<" "<<month<<" "<<day;
        
        return 0;
    }
    
  • 1

信息

ID
1003
难度
6
分类
(无)
标签
递交数
785
已通过
193
通过率
25%
被复制
8
上传者