Shift hill

P2010 [NOIP2016 普及组] 回文日期

DDV1 @ 2024-08-21 16:51:02

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
    int da1,da2,ans=0;
    cin>>da1>>da2;
    int y=da1/10000,endy=da2/10000;
    da1%=10000;da2%=10000;
    int m=da1/100,endm=da2/100;
    da1%=100;da2%=100;
    int d=da1,endd=da2;
//  cout<<y<<" "<<m<<" "<<d<<"\n";
//  cout<<endy<<" "<<endm<<" "<<endd<<"\n";
    for(;;){
        if((m%2==1)&&(m<8)){
            d++;
            if(d>31){
                d=1;
                m++;
            }
        }
        else if((m%2==1)&&(m>8)){
            d++;
            if(d>30){
                d=1;
                m++;
            }
        }
        else if((m%2==0)&&(m<8)&&(m!=2)){
            d++;
            if(d>30){
                d=1;
                m++;
            }
        }
        else if((m%2==0)&&(m>=8)){
            d++;
            if(d>31){
                d=1;
                m++;
            }
        }
        else if(((m==2)&&(y%4!=0))||((m==2)&&(y%4==0)&&(y%100==0)&&(y%400!=0))){
            d++;
            if(d>28){
                d=1;
                m++;
            }
        }
        else if(((m==2)&&(y%4==0)&&(y%100!=0))||((m==2)&&(y%400==0))){
            d++;
            if(d>29){
                d=1;
                m++;
            }
        }
        int a[9],l=4,yf=y,mf=m,df=d;
        while(yf){
            a[l]=yf%10;
            yf/=10;
            l--;
        }
        l=6;
        while(mf){
            a[l]=mf%10;
            mf/=10;
            l--;
        }
        l=8;
        while(df){
            a[l]=df%10;
            df=10;
            l--;
        }
        if(m<10)
            a[5]=0;
        if(d<10)
            a[7]=0;
        if(m>12){
            m=1;
            d=1;
            y++;
        }
        if(a[1]==a[8]&&a[2]==a[7]&&a[3]==a[6]&&a[4]==a[5]){
            ans++;
        }
        cout<<y<<m<<d<<endl;
        if(y==endy && m==endm && d==endd)
        break;
    }
    cout<<ans;
    return 0; 
}

|