73分8,9,10WA,求解,谢谢

P2010 [NOIP2016 普及组] 回文日期

biophitma_wby @ 2022-09-28 20:20:53

下载样例8 输出i后竟然出现

23200232

24200242

25200252

26200262

27200272

28200282

29200292 帮忙看一下哪里有问题,谢谢!

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
long long a,b;
bool Runnian(int k){
    if((k%4==0&&k%100!=0)||k%400==0){
        return true;
    }
    return false;
}
bool Huiwen(int k){
    int t=0,f=k;
    while(f!=0){
        t=t*10+f%10;
        f=f/10;
    }
    if(k==t)return true;
    else return false;
}
int sum=0;
int main(){
    cin>>a>>b;
//  20161119
    for(long long i=a;i<=b;){
        int k1=i%10000/100;
        int k2=i%100;
        if((k1==1||k1==3||k1==5||k1==7||k1==8||k1==10||k1==12)&&k2==32){
            i+=100;
            i-=31;
            int k3=i%10000/100;
            if(k3==13){
                i-=1200;
                i+=10000;
            }
        }else{
            if((k1==4||k1==6||k1==9||k1==11)&&k2==31){
                i+=100;
                i-=30;
                int k3=i%10000/100;
                if(k3==13){
                    i-=1200;
                    i+=10000;
                }
            }
            else{
                if(k1==2&&Runnian(i)&&k2==30){
                    i+=100;
                    i-=29;
                    int k3=i%10000/100;
                    if(k3==13){
                        i-=1200;
                        i+=10000;
                    }
                }
                else{
                    if(k1==2&&Runnian(i)&&k2==29){
                        i+=100;
                        i-=28;
                        int k3=i%10000/100;
                        if(k3==13){
                            i-=1200;
                            i+=10000;
                        }
                    }
                }
            }
        }
        if(Huiwen(i)==true){
            sum++;
        }
        i+=1;
    }
    cout<<sum;
    return 0;
}

by liujunhongljh @ 2022-09-28 21:21:39

%%%


by biophitma_wby @ 2022-10-03 15:34:51

改对了,原来我闰年一直判断错了,嘿嘿嘿

k1==2&&Runnian(i)&&k2==30
k1==2&&Runnian(i)&&k2==29

|