不理解
查看原帖
不理解
945549
jwsdy楼主2023/8/22 07:26

此题正解蒟蒻已过,但是为啥此代码最后一个测试点总过不了???

using namespace std;
int d1,d2,ans=0;
int main(){
    ios::sync_with_stdio(false);
    cin>>d1>>d2;
    int n1=d1/10000;
    int n2=d2/10000;
    int r1=d1%10000;
    int r2=d2%10000;
    if(d1==d2){
        int b1=d1/10000000;
        int b2=d1%10000000/1000000;
        int b3=d1%1000000/100000;
        int b4=d1%100000/10000;
        int b5=d1%10000/1000;
        int b6=d1%1000/100;
        int b7=d1%100/10;
        int b8=d1%10;
        if(b1==b8&&b2==b7&&b3==b6&&b4==b5)
        cout<<1;
        else
        cout<<0;
        return 0;
    }
    for(int i=n1;i<=n2;i++){
        int a1=i/1000;
        int a2=i%1000/100;
        int a3=i%100/10;
        int a4=i%10;
        int x=a4*10+a3;
        int y=a2*10+a1;
        int z=a4*10000+a3*100+a2*10+a1;
        if(i==n1&&z>=r1){
            if(x>=1&&x<=12){
            if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
                if(y>=1&&y<=31)
                ans++;
            }
            else if(x==2){
                if((i%100!=0&&i%4==0)||i%400==0){
                    if(y>=1&&y<=29)
                    ans++;
                }
                else if(y>=1&&y<=28)
                    ans++;
            }
            else if(x==4||x==6||x==9||x==11){
                if(y>=1&&y<=30)
                ans++;
            }
        }
        }
        else if(i==n2&&z<=r2){
            if(x>=1&&x<=12){
            if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
                if(y>=1&&y<=31)
                ans++;
            }
            else if(x==2){
                if((i%100!=0&&i%4==0)||i%400==0){
                    if(y>=1&&y<=29)
                    ans++;
                }
                else if(y>=1&&y<=28)
                    ans++;
            }
            else if(x==4||x==6||x==9||x==11){
                if(y>=1&&y<=30)
                ans++;
            }
        }
        }
        else if(x>=1&&x<=12){
            if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
                if(y>=1&&y<=31)
                ans++;
            }
            else if(x==2){
                if((i%100!=0&&i%4==0)||i%400==0){
                    if(y>=1&&y<=29)
                    ans++;
                }
                else if(y>=1&&y<=28)
                    ans++;
            }
            else if(x==4||x==6||x==9||x==11){
                if(y>=1&&y<=30)
                ans++;
            }
        }
    }
    cout<<ans;
    return 0;
}
2023/8/22 07:26
加载中...