求大神指教,70分

P2010 [NOIP2016 普及组] 回文日期

不以己悲 @ 2017-08-30 11:41:10

#include<iostream>
#include<cstdio>
#include<cstring> 
using namespace std;
int month(int a)
{
    if(a==1||a==3||a==5||a==7||a==8||a==10||a==12)
    return 1;
    else
    return 2;
}
int main()
{
    char a1[3],a2[3],a5[7],a6[7],a7[7];
    gets(a5);gets(a6);
    int m,n,sum=0;
    for(int i=0;i<4;i++){a1[i]=a5[i];a2[i]=a6[i];}
    sscanf(a1,"%d",&m);
    sscanf(a2,"%d",&n);
    for(int i=m;i<=n;i++)
    {
        sprintf(a7,"%d",i);
        for(int j=4;j<=7;j++)
        a7[j]=a7[7-j];
      int x=(int)(a7[4]-'0')*10+(int)(a7[5]-'0');
      int y=(int)(a7[6]-'0')*10+(int)(a7[7]-'0');
      int x1=(int)(a6[4]-'0')*10+(int)(a6[5]-'0');
      int y1=(int)(a6[6]-'0')*10+(int)(a6[7]-'0');
        if(x>12||y>31||(month(x)==2&&y>30)||(x==2&&y>29)||x==0||y==0)
        continue;
        else if(x<=x1||x==x1&&y<=y1)
        sum++;
}
    cout<<sum;
    return 0;
}

by Freddie @ 2017-10-16 18:26:38

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int b,c;
    cin>>b>>c;
    int mas=0,year[3],date[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    year[1]=b/10000;
    year[2]=c/10000;
    for(int i=year[1];i<=year[2];i++)
    {
        int ye,da;
        ye=i/100;
        da=i-ye*100;
        ye=ye/10+ye%10*10;
        da=da/10+da%10*10;int kkk=ye;
        ye=da;da=kkk;
        //cout<<ye<<" "<<da<<endl;
        if(ye>0&&ye<13)
        {
            int dd=0;
            if(i%4==0&&ye==2)
                dd++;
            if(1<=da&&da<=date[ye]+dd)
            {
                mas++;
                //cout<<"i:"<<i<<endl;
            }
        }    
    }
    cout<<mas;
    return 0;
}

|