请哪位巨lao帮本蒟蒻优化一下代码,谢谢

P2010 [NOIP2016 普及组] 回文日期

Naruto_steven @ 2018-11-08 18:10:03

//20000101
//cdefghkq
//20101231

/*20000101
20101231*/
#include<iostream>
using namespace std;
#define ll long long
int r[14]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int y[14]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
    ll a,b,ans=0;
    cin>>a>>b;
    for(ll i=a;i<=b;i++){
        int c=i/10000000;
        int d=(i%10000000)/1000000;
        int e=(i%1000000)/100000;
        int f=(i%100000)/10000;
        int g=(i%10000)/1000;
        int h=(i%1000)/100;
        int k=(i%100)/10;
        int q=i%10;
        if(((c*1000+d*100+e*10+f)%4==0&&(c*1000+d*100+e*10+f)%100!=0)||((c*1000+d*100+e*10+f)%400==0)){
            if((g*10+h)>12||(k*10+q>y[g*10+h])){
                continue;
            }else{
                if(c==q&&d==k&&e==h&&f==g) ans++;
            }   
        }else{
            if((g*10+h)>12||(k*10+q>r[g*10+h])){
                continue;
            }else{
                if(c==q&&d==k&&e==h&&f==g) ans++;
            }
        }
    }
    cout<<ans;  
    return 0;
} 
//c==q&&d==k&&e==h&&f==g

by Zeril @ 2018-11-08 18:16:43

当年我纯模拟的,用大佬sweetlemon的话说就是枚举前4个数字再数位翻转,check一下日期是否合法就行了


|