Error求助

P2010 [NOIP2016 普及组] 回文日期

songyuan888 @ 2019-08-24 14:04:04

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int a,i,j,d[19],h,e,c,na,s,t,hh,y[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},ya,ra,nb,yb,rb,k,b;
    bool g;
    cin>>a>>b;
    na=a/10000;
    ya=a%10000/100;
    ra=a%100;
    nb=b/10000;
    yb=b%10000/100;
    rb=b%100;
    s=0;
    for(i=na;i<=nb;i++)
    {
        if((i%4==0&&i%100!=0)||i%400==0)
        {
            for(j=1;j<=12;j++)
            {
                if(j==2)
                {
                    for(k=1;k<=29;k++)
                    {
                        hh=0;
                        g=0;
                        t=i*10000+j*100+k;
                        c=t;
                        while(t!=0)
                        {
                            h=t%10;
                            hh++;
                            d[hh]=h;
                            t=t/10;
                        }
                        for(e=1;e<=hh;e++)
                        {
                            if(d[e]!=d[hh-e+1])
                            {
                                g=1;
                                break;
                            }
                        }
                        if(g==0)
                            s++;    
                    }
                }
                else
                {
                    for(k=1;k<=y[i];k++)
                    {
                        hh=0;
                        g=0;
                        t=i*10000+j*100+k;
                        c=t;
                        while(t!=0)
                        {
                            h=t%10;
                            hh++;
                            d[hh]=h;
                            t=t/10;
                        }
                        for(e=1;e<=hh;e++)
                        {
                            if(d[e]!=d[hh-e+1])
                            {
                                g=1;
                                break;
                            }
                        }
                        if(g==0)
                            s++;
                    }
                }
            }
        }
        else
        {
            for(k=1;k<=y[i];k++)
            {
                hh=0;
                g=0;
                t=i*10000+j*100+k;
                c=t;
                while(t!=0)
                {
                    h=t%10;
                    hh++;
                    d[hh]=h;
                    t=t/10;
                }
                for(e=1;e<=hh;e++)
                {
                    if(d[e]!=d[hh-e+1])
                    {
                        g=1;
                        break;
                    }
                }
                if(g==0)
                    s++;
            }
        }
    }
    return 0;
}

by Smile_Cindy @ 2019-08-24 14:18:04

@songyuan888

没那么麻烦。

#include <bits/stdc++.h>
using namespace std;
bool is_leap(int x)
{
    return x%4==0 && x%100 || x%400==0;
} 
int month(int y,int m)
{
    switch(m)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:return 31;
        case 2:return 28+is_leap(y);
        default:return 30;
    }
}
int main()
{
    int sy,sm,sd;
    int ey,em,ed;
    int d1,d2;
    cin>>d1>>d2;
    sy=d1/10000,sm=d1%10000/100,sd=d1%100;
    ey=d2/10000,em=d2%10000/100,ed=d2%100;
    int ans=0;
    for(int i=sy;i<=ey;i++)
    {
        int mon=i%10*10+i%100/10;
        int day=i/1000+i%1000/100*10;
        if(mon<1||mon>12)continue;
        if(day<1||day>month(i,mon))continue;
        if(i==ey)
        {
            if(mon>em)continue;
            else if(mon==em&&day>ed)continue;
        }
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

by C3765428 @ 2019-08-24 14:31:19

#include<iostream>
using namespace std;
int main(){
int a[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int sy,ey,y,m=1,d=1;
cin>>sy>>ey;
int ans=0;
for(int i=1;i<=12;i++){
    for(int j=1;j<=a[i];j++) {
        y=j%10*1000+j/10%10*100+i%10*10+i/10;
        y=y*10000+i*100+j;
        if(y>=sy&&y<=ey){
            ans++;
        }
    }
}
cout<<ans;
    return 0;
}

by songyuan888 @ 2019-08-24 14:37:26

谢谢大家。


by songyuan888 @ 2019-08-24 14:38:26

@C3765428 平年呢?


|