64

P2010 [NOIP2016 普及组] 回文日期

Paris_Commune @ 2022-02-14 13:17:28

//
#include <cstdio>
int l,r,year,month,day;
bool judge(int n){
    year=n/10000;
    month=n%10000/100;
    day=n%100;
    if(n<l||n>r)return false;
    if(day>=32||month>=13)return false;
    if(day==31&&(month==2||month==4||month==6||month==9||month==11))return false;
    if(day==30&&month==2)return false;
    if(day==29&&month==2)
        if(year%400==0||year%4==0&&year%100!=0)return true;
        else return false;
    return true; 
}
using namespace std;
int main(){

    int ly,ry,tot=0;
    scanf("%d%d",&l,&r);
    ly=l/10000;
    ry=r/10000;
    for(int i=ly;i<=ry;i++){
        if(judge(i*10000+i%10*1000+i%100/10*100+i%1000/100*10+i/1000)==1)
        tot++;
    }
    printf("%d",tot);    
    return 0;
}

by RockyYue @ 2022-02-14 13:43:35

@LHC427 要加一个判断,看看month和day是不是0的。比如2100反过来就是0012,月为0,非法。


by Paris_Commune @ 2022-02-14 20:05:51

@RockyYue_ 谢谢!!!


by RockyYue @ 2022-02-14 20:15:40

@LHC427 不用谢qwq


by RockyYue @ 2022-02-14 20:16:23

@LHC427 CSDN&lg 互关/kk


by Paris_Commune @ 2022-02-14 21:25:58

你的CSDN账号??

洛谷关注了

我的CSDN: LHC427

过了


|