100分求助(Subtask #1不对)

P2010 [NOIP2016 普及组] 回文日期

yuxinrui0618 @ 2024-09-15 13:25:46

测试点下载了,20110101 20110105,正确输出0,我输出1,大佬帮忙看下

#include<bits/stdc++.h>
using namespace std;
bool run(long long x)
{
    if(x%400==0||(x%4==0&&x%100!=0))
        return true;
    return false;
}
int main()
{
    long long sum=0;
    long long a,b;
    cin>>a>>b;
    long long n1=a/10000;
    long long n2=b/10000;
    for(long long i=n1;i<=n2;i++)
    {
        long long t1=(i%10*10+i/10%10);
        long long t2=(i/100%10*10+i/1000);
        if(((t1==1 || t1==3 || t1==5 || t1==7 || t1==8 || t1==10 || t1==12)&&(t2<=31))||((t1==4||t1==6||t1==9||t1==11) && (t2<=30)) || (t1==2 && run(i)) && (t2<=29) || (t1==2 && !run(i)) && (t2<=28))
            sum++;
    }
    cout<<sum<<endl;
}

by abc20131113 @ 2024-09-16 16:46:28

@yuxinrui0618 斯......好像是一百分耶


by abc20131113 @ 2024-09-16 16:49:11

@yuxinrui0618 这样吧,我把我代码发给你,你看看。下面是代码:


#include<iostream>
using namespace std;
int y[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
    int f,t;
    cin>>f>>t;
    int year=f/10000;
    int m=f%10000/100;
    int day=f%100;
    int sum=0;
    while(year*10000+m*100+day<=t){
        if(year%400==0||year%100!=0&&year%4==0){
            y[2]=29;
        }
        else{
            y[2]=28;
        }
        int a,b,c,d;
        d=m/10;
        c=m%10;
        b=day/10;
        a=day%10;
        if(d+10*c+100*b+1000*a==year){
            sum++;
        }
        if(day+1>y[m]){
            day=0;
            m++;
        }
        if(m>12){
            m=1;
            year++;
        }
        day++;
    }
    cout<<sum;
    return 0;
}

|