4 条题解

  • 1
    @ 2022-08-08 15:35:36

    //八格牙路!!! 不通过就进村!!!

    #include<iostream>
    using namespace std;

    class Date
    {
    private:
    int year;
    int month;
    int day;
    public:
    Date(int y,int m,int d)
    {
    year=y;
    month=m;
    day=d;
    }

    int is_leap_year()
    {
    if(year%400==0 || (year%4==0&&year%100!=0))
    return 1;
    return 0;
    }

    int day_left()
    {
    int Month[13]={0,31,28+is_leap_year(),31,30,31,30,31,31,30,31,30,31};
    int sum=0;
    for(int i=0;i<month;i++)
    sum=sum+Month[i];
    sum=sum+day;
    return sum;
    }
    };

    int main()
    {
    int year,month,day;
    cin>>year>>month>>day;
    Date date(year,month,day);
    cout<<date.day_left()<<endl;

    system("pause");
    return 0;
    }

  • -1
    @ 2021-01-27 11:46:46

    #include <iostream>
    using namespace std;

    int main()
    {
    int year,month,day, leap,sum=0;
    cin>>year>>month>>day;
    int r4=year%4;
    int r100=year%100;
    int r400=year%400;
    if(r400==0 || (r4==0 && r100!=0) )
    leap=1;
    else
    leap=0;
    sum=sum+day;

    month=month-1;
    while(1)
    {
    if(month==11)
    sum=sum+30;
    if(month==10)
    sum=sum+31;
    if(month==9)
    sum=sum+30;
    if(month==8)
    sum=sum+31;
    if(month==7)
    sum=sum+31;
    if(month==6)
    sum=sum+30;
    if(month==5)
    sum=sum+31;
    if(month==4)
    sum=sum+30;
    if(month==3)
    sum=sum+31;
    if(month==2)
    sum=sum+28+leap;
    if(month==1)
    sum=sum+31;
    if(month==0)
    break;
    month--;
    }
    cout<<sum<<endl;
    return 0;
    }

  • -1
    @ 2021-01-25 17:44:00
    #include<iostream>
    using namespace std;
    int main()
    {
        int year,month,day;
        int xvx,all_day;//这个是总天数(工地英语)
        cin>>year>>month>>day;
        all_day=day;
        if((year%4==0&&year%100!=0)||(year%400==0))//判断闰年
            xvx=1;
        else
            xvx=0;
        
        switch(month-1)//switch特性
        {
            case 11:all_day+=30;
            case 10:all_day+=31;
            case 9:all_day+=30;
            case 8:all_day+=31;
            case 7:all_day+=31;
            case 6:all_day+=30;
            case 5:all_day+=31;
            case 4:all_day+=30;
            case 3:all_day+=31;
            case 2:all_day+=28+xvx;
            case 1:all_day+=31;
            
            
        }
        cout<<all_day;
            
        return 0;
    }
    
  • -1
    #include<iostream>
    using namespace std;
    
    class Date
    {
    private:
        int year;
        int month;
        int day;
    public:
        Date(int y,int m,int d)
        {
            year=y;
            month=m;
            day=d;
        }
    
        int is_leap_year()
        {
            if(year%400==0 || (year%4==0&&year%100!=0))
                return 1;
            return 0;
        }
    
        int day_left()
        {
            int Month[13]={0,31,28+is_leap_year(),31,30,31,30,31,31,30,31,30,31};
            int sum=0;
            for(int i=0;i<month;i++)
                sum=sum+Month[i];
            sum=sum+day;
            return sum;
        }
    };
    
    int main()
    {
        int year,month,day;
        cin>>year>>month>>day;
        Date date(year,month,day);
        cout<<date.day_left()<<endl;
    
        system("pause");
        return 0;
    }
    
  • 1

A1-4 分支结构练习:今年过去了多少天

信息

难度
5
分类
(无)
标签
递交数
957
已通过
345
通过率
36%
被复制
14
上传者