80分求调

P2010 [NOIP2016 普及组] 回文日期

summer112786 @ 2024-11-17 22:48:26

#include <bits/stdc++.h>
using namespace std;

int a,b;//开始 结束
int ans=0;
//01234567
//20221231

bool typ(int a){
    if((a%4==0&&a%100!=0)||a%400==0){
        return true;
    }
    return false;
}

void add(){
    int year=(a-(a%10000))/10000;
    int month=(a%10000-a%100)/100;
    int day=a%100;

    if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&day==31){
        a=year*10000+(month+1)*100+1;
    }
    else if((month==4||month==6||month==9||month==11)&&day==30){
        a=year*10000+(month+1)*100+1;
    }
    else if(typ(year)&&month==2&&day==28){
        a=year*10000+(month+1)*100+1;
    }else if(!typ(year)&&month==2&&day==29){
        a=year*10000+(month+1)*100+1;
    }else{
        a=year*10000+month*100+day+1;
    }

    if(month==12&&day==31){
        a=(year+1)*10000+101;
    }
//  cout<<a<<endl;
}
void juge(int x){//20221213
    int a1,a2,a3,a4,a5,a6,a7,a8;
    a1=(x-x%10000000)/10000000;
    a2=(x%10000000-x%1000000)/1000000;
    a3=(x%1000000-x%100000)/100000;
    a4=(x%100000-x%10000)/10000;
    a5=(x%10000-x%1000)/1000;
    a6=(x%1000-x%100)/100;
    a7=(x%100-x%10)/10;
    a8=a%10;

    if(a1==a8&&a2==a7&&a3==a6&&a4==a5){
        cout<<a1<<a2<<a3<<a4<<"年"<<a5<<a6<<"月"<<a7<<a8<<"日"<<endl;
//      cout<<1;
        ans++;
    }
}

int main(){
    cin>>a>>b;
//  cout<<endl;
    juge(a);
    while(a!=b){
        add();
        juge(a);
    }
    if(a!=b){
        juge(b);
    }

    cout<<ans;

}

|