60分求助

P2010 [NOIP2016 普及组] 回文日期

evil_paramecium @ 2023-09-12 18:58:37

#include<bits/stdc++.h>

using namespace std;
long long a1,a2,a3,b1,b2,b3,j=1000,js;
char a[9],b[9];
int main(){
    /*freopen("date.in","r",stdin);
    freopen("date.out","w",stdout);*/
    cin>>a>>b;
    for(int i=0;i<4;i++){
        int uu=a[i]-48;
        a1+=uu*j;
        j/=10;
    }
    j=10;
    for(int i=4;i<6;i++){
        int uu=a[i]-48;
        a2+=uu*j;
        j/=10;
    }
    j=10;
    for(int i=6;i<8;i++){
        int uu=a[i]-48;
        a3+=uu*j;
        j/=10;
    }
    j=1000;
    for(int i=0;i<4;i++){
        int uu=b[i]-48;
        b1+=uu*j;
        j/=10;
    }
    j=10;
    for(int i=4;i<6;i++){
        int uu=b[i]-48;
        b2+=uu*j;
        j/=10;
    }
    j=10;
    for(int i=6;i<8;i++){
        int uu=b[i]-48;
        b3+=uu*j;
        j/=10;
    }
    if((a1/1000==a3%10) and (a1/100-a1/1000*10==a3/10 or (a3<10 and a1/100-a1/1000*10==0)) and ((a1/10-(a1/1000*100+(a1/100-a1/1000*10)))==a2%10) and (a1%10==a2/10 or (a2<10 and a1%10==0))){
        js++;
        cout<<js;
        return 0;
    }
    while(a1!=b1 or a2!=b2 or a3!=b3){
        if(a2==12 and a3==31){
            a1++;
            a2=1;
            a3=0;
        }
        if(a1%400==0){
            if(a2==2 and a3==28){
                a3+=0;
            }
            if(a2==2 and a3==29){
                a2++;
                a3=0;
            }
        }
        else if(a1%4==0 and a1%100!=0){
            if(a2==2 and a3==28){
                a3+=0;
            }
            if(a2==2 and a3==29){
                a2++;
                a3=0;
            }
        }
        else{
            if(a2==2 and a3==28){
                a2++;
                a3=0;
            }
        }
        if(a2==1 or a2==3 or a2==5 or a2==7 or a2==8 or a2==10 or a2==12){
            if(a3==31){
                a3=0;
                a2++;
            }
        }
        else{
            if(a2!=2){
                if(a3==30){
                    a3=0;
                    a2++;
                }
            }
        }
        a3++;
        if((a1/1000==a3%10) and (a1/100-a1/1000*10==a3/10 or (a3<10 and a1/100-a1/1000*10==0)) and ((a1/10-(a1/1000*100+(a1/100-a1/1000*10)))==a2%10) and (a1%10==a2/10 or (a2<10 and a1%10==0))){
            js++;
        }
    }
    cout<<js;
}

|