60分!求救!

P2010 [NOIP2016 普及组] 回文日期

仙人求我 @ 2017-07-28 17:15:32

#include<iostream>
#include<cstdio>
using namespace std;
int year,S=0,x,date1,date2,i,a,b,c,d,e,f,g,h,k,l;
int alpha(int w)
{
    if(w%400==0||(w%100!=0&&w%4==0))
        return 1;
    else return 0;
}
int main()
{
    scanf("%d%d",&date1,&date2);
    if(date1==date2)
        {
            a=date1/10000000;
            b=date1/1000000%10;
            c=date1/100000%10;
            d=date1/10000%10;
            e=date1/1000%10;
            f=date1/100%10;
            g=date1/10%10;
            h=date1%10;
            if(a==h&&b==g&&c==f&&d==e)
                printf("1");
            else
                printf("0");
        }
    if(date1!=date2)
        {
            for(i=date1;i<=date2;i++)
                {
                    x=i;
                    a=x/10000000;
                    b=x/1000000%10;
                    c=x/100000%10;
                    d=x/10000%10;
                    e=x/1000%10;
                    f=x/100%10;
                    g=x/10%10;
                    h=x%10;
                    k=e*10+f;
                    l=g*10+h;
                    year=x%10000;
                    if(k<=12||((k==4||k==6||k==9||k==11)&&l<=30)||((k==1||k==3||k==5||k==7||k==8||k==10||k==12)&&l<=31))
                        if(a==h&&b==g&&c==f&&d==e)
                            S++;
                    if(k==2)
                        {
                            if(alpha(year)==1&&l<=29)
                                if(a==h&&b==g&&c==f&&d==e)
                                    S++;    
                            else 
                                if(alpha(year)==0&&l<=28)
                                    if(a==h&&b==g&&c==f&&d==e)
                                        S++;
                        }
                }
            printf("%d",S);
        }
    return 0;
}

by FQLtreap @ 2017-07-30 10:46:18

月份为零特判


|