30分求助

P2010 [NOIP2016 普及组] 回文日期

fxsnbfx @ 2024-04-24 23:01:45


#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int N=20;
int month[N]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main()
{
    ll st,ed,num=0;
    cin>>st>>ed;
    ll date=st,key=0,y=st/1000;
    while(1)
    {
        for(int i=1;i<=12;i++)
        {
            for(int j=1;j<=month[i];j++)
            {
                date=y*1000+i*100+j;
                int flag=0;
                if((y/1000==j%10)&&(y/100%10==j/10)&&(y/10%10==i%10)&&(y%10==i/10))
                flag=1;
                if(date>=st&&date<=ed&&flag)
                 num++;
                if(date>ed)
                 key=1;
            }
        }
        y++;
        if(key)
        break;
    }
    cout<<num;
    return 0;
}

|