5 条题解

  • 1
    @ 2021-02-12 13:27:17
    #include <iostream>
    using namespace std;
    int main()//水题
    {
        int y,m,leap;cin>>y>>m;
        if(y%4==0&&y%100!=0||y%400==0)
            leap=1;
        else
            leap=0;
        int a[12]={31,28+leap,31,30,31,30,31,31,30,31,30,31};
        cout<<a[m-1];
        return 0;
    }
    
  • 0

    #include <iostream>
    using namespace std;
    /*
    if(a<b)
    ;
    else
    ;
    */
    int main()
    {
    int year,month, leap, day;
    cin>>year>>month;
    int r4=year%4;
    int r100=year%100;
    int r400=year%400;
    if(r4==0)
    if(r100==0)
    if(r400==0)
    leap=1; // 1600 2000
    else
    leap=0; // 1900 2100
    else
    leap=1; // 1988 2020
    else
    leap=0; // 2021 2022 2023

    // 关系表达式 == > >= < <= !=
    // 逻辑表达式 ||或者 &&并且 !取反
    if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
    day=31;
    else
    if(month==2)
    day=28+leap;
    else
    day=30;
    cout<<day<<endl;
    return 0;
    }
    /*
    */

  • -1

    #include <iostream>
    using namespace std;
    int main()
    {
    int y,m,d,a;
    cin>>y;
    cin>>m;

    if(y%4==0&&y%100!=0||y%400==0)
    a=1;
    else
    a=0;

    if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
    d=31;
    else
    {
    if(m==2)
    d=28+a;
    else
    d=30;
    }
    cout<<d<<endl;
    return 0;
    }

  • -2

    #include <iostream>
    using namespace std;
    int main()
    {
    int year,month, leap, day;
    cin>>year>>month;
    int r4=year%4;
    int r100=year%100;
    int r400=year%400;
    if(r400==0||(r4==0&&r100!=0) )
    leap=1;
    else
    leap=0;
    if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
    day=31;
    else
    if(month==2)
    day=28+leap;
    else
    day=30;
    cout<<day<<endl;
    return 0;
    }

  • -3

    #include <iostream>
    using namespace std;

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

    else
    leap=0;

    else
    leap=1;
    else
    leap=0;

    if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
    day=31;
    else
    if(month==2)
    day=28+leap;
    else
    day=30;
    cout<<day<<endl;
    return 0;
    }

  • 1

A1-3 分支结构练习:月份天数

信息

难度
7
分类
(无)
标签
递交数
3261
已通过
689
通过率
21%
被复制
10
上传者