求救70分

P2010 [NOIP2016 普及组] 回文日期

0_0_0_0_0_0 @ 2017-07-09 21:33:07

#include<iostream>
using namespace std;
int ppap(int pen)
{
    int q,s=0;
    q=pen;
    for(int i=1;i<=4;i++)
    {
            s=s*10+q%10;
            q/=10;
    }
    return s;   
}
bool sfd(int s)
{
     int s1,s2,ss,xz;
     s1=s/100;s2=s%100;
     ss=ppap(s);
     if(s1==2)
     {
              if(((ss%4==0&&ss%100!=0)||ss%400==0))xz=29;else xz=28;
     }
     if(s1==1||s1==3||s1==5||s1==7||s1==8||s1==10||s1==12)xz=31;
     if(s1==4||s1==6||s1==9||s1==11)xz=30;
     if(s2<=xz&&s1<=12)return true;else return false;
}    
int main()
{
    int m,n,m1,m2,n1,n2,ss=0;
    cin>>m>>n;
    m1=m/10000;m2=m%10000;
    n1=n/10000;n2=n%10000;
    if(m==n)
    {
            if(ppap(m1)==m2)cout<<"1";return 0;
    }
    if(m!=n)
    {
            for(int i=m1;i<=n1;i++)
            {
                    if(i%10>1||(i%10==1&&i/10%10>2)||i/100%10>3||(i/100%10==3&&i/1000>1))continue;
                    if(sfd(ppap(i))==true&&(i*10000+ppap(i)>=m)&&(i*10000+ppap(i)<=n))ss++;
            }   
    }
    cout<<ss;
    return 0;
}

by 王健阳 @ 2017-07-17 20:02:03

这么打会时间超限


by 王健阳 @ 2017-07-17 20:13:31

#include<cstdio>
int a[11000];
int p[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int r[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
/*int hw(int x)
{
    int k=0;
    while(x!=0)
    {
        int m=x%10;
        k++;
        a[k]=m;
        x=x/10;
    } 
    for(int i=1;i<=k/2;i++)
    {
        if(a[i]!=a[k-i+1])
        {
            return 0;
        }
    }
    return 1;
}*/
int pd(int x)
{
    int n=x/10000;
    int m=x%10000/100;
    int k=x%100;
    if((n%4==0&&n%100!=0)||n%400==0)
    {
        if(m>=1&&m<=12)
        {
            if(k>=1&&k<=r[m])
            {
                return 1;
            }
        }
    }
    else
    {
        if(m>=1&&m<=12)
        {
            if(k>=1&&k<=p[m])
            {
                return 1;
            }
        }
    }
    return 0;
}
int hw2(int x)
{
    int k=0,s=0;
    while(x!=0)
    {
        a[++k]=x%10;
        x=x/10;
    }
    for(int i=k;i>=1;i--)
    {
        s=s*10;
        s=s+a[i];
    }
    for(int i=1;i<=k;i++)
    {
        s=s*10;
        s=s+a[i];
    }
    return s;
}
int main()
{
    int n,m,s=0;
    scanf("%d %d",&n,&m);
    int a=n/10000,b=m/10000;
    for(int i=a;i<=b;i++)
    {
        if(pd(hw2(i))==1) 
        {
            s++;
        }
    }
    printf("%d",s);
}

|