50求助,样例无法输出结果,求看思路哪里有问题~

P2010 [NOIP2016 普及组] 回文日期

77Glorious @ 2024-04-24 16:06:10


#include<bits/stdc++.h>
using namespace std;
int pn[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},rn[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
bool hw(int a)
{
    int tmp=0,x=a,p=10000000;
    while(x!=0)
    {
        tmp+=x%10*p;
        x/=10;
        p/=10;
    }
    if(tmp==a) return 1;
    return 0;
}
bool isrn(int x)
{
    if(x%400==0) return 1;
    if(x%4==0 && x%100!=0) return 1;
    return 0;
}
int a,b,cnt;
int main()
{
    int a,b;
    cin>>a>>b;
    int y1=a/10000,m1=a%10000/100,d1=a%100;//年月日 
    int y2=b/10000,m2=b%10000/100,d2=b%100;
    for(int i=y1;i<=y2;i++)
    {
        if(!isrn(i))//平年用平年数组 
        {
            for(int j=m1;j<=12;j++)
                for(int k=d1;k<=pn[j];k++)
                {
                    if(i*10000+j*100+k>b)//年月日加起来大于目标数就输出答案 
                    {
                        cout<<cnt; return 0;
                    }
                    else if(hw(i*10000+j*100+k))cnt++;
                }
        }
        else //闰年 
        {
            for(int j=m1;j<=12;j++)
                for(int k=d1;k<=rn[j];k++)
                {
                    if(i*10000+j*100+k>b)
                    {
                        cout<<cnt; return 0;
                    }
                    else if(hw(i*10000+j*100+k))cnt++;
                }           
        }
    }
}

by sdjy20120918 @ 2024-04-24 16:40:53

@77Glorious 你能加我吗?我现在很想加洛谷的朋友


by sunrunjie @ 2024-07-06 17:32:24

@77Glorious

#include<bits/stdc++.h>
using namespace std;
int a[30]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
    int x,y,ans=0;
    cin>>x>>y;
    for(int i=1;i<=12;i++){
        for(int j=1;j<=a[i];j++){
            int g,s,b,q;
            g=j%10;
            s=j/10;
            b=i%10;
            q=i/10;
            int sum=g+s*10+b*100+q*1000+q*10000+b*100000+s*1000000+g*10000000;
            if(sum>=x&&sum<=y){
                ans++;
            }
        }
    }
    cout<<ans;
}

求关注


by 77Glorious @ 2024-07-08 19:52:20

@sunrunjie 已解决~


by sunrunjie @ 2024-07-11 10:07:50

@77Glorious 你给个关注呗


|