1 条题解

  • 0
    @ 2025-4-12 21:41:02

    C :

    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
    	int y,m,a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        scanf("%d%d",&y,&m);
        if(m!=2)
            printf("%d",a[m]);
        if(m==2)
            if(y%4==0 || y%400==0)
                printf("29");
            else
                printf("28");
    	return 0;
    }
    
    

    C++ :

    #include <iostream>
    #include <cstdio>
    using namespace std;
    int main()
    {
        int year,month;
        cin>>year>>month;
        switch (month)
        {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                cout<<31<<endl;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                cout<<30<<endl;
                break;
            default:
                //2月
                if( (year%100 != 0  && year%4 == 0) || (year%400 == 0) )
                {
                    //如果是闰年,2月29天
                    cout<<29<<endl;
                }
                else
                {
                    //如果是平年,2月28天
                    cout<<28<<endl;
                }
                break;
        }
        return 0;
    }
    

    Pascal :

    program xx;
    var year,month,days:integer;
    begin
    read(year,month);
    case month of
        1,3,5,7,8,10,12: days:=31;
        4,6,9,11       : days:=30;
        2              : if (year mod 4=0)and(year mod 100 <>0)
                            or(year mod 400=0)
                            then days:=29
                            else days:=28
    end;
    writeln(days);
    end.
    
    • 1

    信息

    ID
    1057
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者