11过不了,下载数据自测又没有问题,哪位帮忙看看,谢谢。

P2010 [NOIP2016 普及组] 回文日期

zlfpass @ 2023-06-15 16:33:27

date1=input()
date2=input()
aa=[0,31,29,31,30,31,30,31,31,30,31,30,31]
bb=[0,31,28,31,30,31,30,31,31,30,31,30,31]
year1=date1[:4]
year2=date2[:4]

def qn(year1,year2):       
    n=0
    while int(year1)<=int(year2):

            #print(int(year1[::-1][:2]))
            if int(year1[::-1][:2])<1 or int(year1[::-1][:2])>12:
                    year1=str(int(year1)+1)
                    #print(year1)

            else:
                    #print("xia",year1)
                    if (int(year1)%4==0 and int(year1)%100!=0) or (int(year1)%4==0):
                        for i in range(1,len(aa)):
                            for j in range(1,aa[i]+1):
                                if (year1+str(i).zfill(2)+str(j).zfill(2))==(year1+str(i).zfill(2)+str(j).zfill(2))[::-1]:
                                    #print((year1+str(i).zfill(2)+str(j).zfill(2)))

                                    n+=1
                                    #print(n)
                                if (year1+str(i).zfill(2)+str(j).zfill(2))==date2:
                                    return n

                    else:
                        for i in range(1,len(bb)):
                            for j in range(1,bb[i]+1):
                                if (year1+str(i).zfill(2)+str(j).zfill(2))==(year1+str(i).zfill(2)+str(j).zfill(2))[::-1]:
                                    #print((year1+str(i).zfill(2)+str(j).zfill(2)))
                                    n+=1
                                    #print(n)
                                if (year1+str(i).zfill(2)+str(j).zfill(2))==date2:
                                    return n
                    year1=str(int(year1)+1)
    return n
n=qn(year1,year2)
print(n)

by HLR20120422 @ 2023-06-15 17:08:05

#include <iostream>
#include <string>
using namespace std;
class _
{
    public:
        int y;
        int m;
        int d;
        string ymd;

 };
void split(string s,int &a,int &b,int &c){
            a=(s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
            b=(s[4]-'0')*100+(s[5]-'0');
            c=(s[6]-'0')*100+(s[7]-'0');

         }
bool run(int runnian)
{
    if(runnian%4==0&&runnian%100)return true;
    if(runnian%400==0)return true;
    return false;
}
int main()
{
    int tpl=0;
    _ startday;
    _ endday;
    int nian,yue,ri;
    cin>>startday.ymd>>endday.ymd;
    split(startday.ymd,startday.y,startday.m,startday.d);
    split(endday.ymd,endday.y,endday.m,endday.d);
    int i,s;
    int c=0;
    for(i=startday.y;i<=endday.y;i++)
    {
        nian=i;
        yue=(nian%10)*10+(nian/10%10);
        ri=(nian/100%10)*10+(nian/1000%10);
        c++;
        s=0;
        if(yue>12||yue<1||ri<1||ri>31)s=1;
        if(yue==4||yue==6||yue==9||yue==11)if(ri>30)s=1;
        if(run(nian)==false)if(yue==2)if(ri>28)s=1;
        if(run(nian)==true)if(yue==2)if(ri>29)s=1;
        if(nian==startday.y&&(yue<startday.m&&ri<startday.d))s=1;
        if(nian==endday.y&&(yue>endday.m&&ri>endday.d))s=1;
        c=c-s;
    }
    cout<<c<<endl;
} 

|