???

P2010 [NOIP2016 普及组] 回文日期

littlefrog @ 2019-08-16 11:47:45

#include <bits/stdc++.h>
using namespace std;
int a,b,c,d;
int e,f;
bool runnian(int year) {
    if(year%100==0) {
        if(year%400==0) {
            return 1;
        }
        return 0;
    }//千禧年特判
    else {
        if(year%4==0) {
            return 1;
        }
        return 0;
    } 
}
bool judge(int n) {
    if(n==1||n==3||n==5||n==7||n==8||n==10||n==12) {
        return 1;
    }
    return 0;
}
bool in(int year,int month,int day) {
    if(year<a||year>d) {
        return 0;
    }
    if((month<b||month>e)&&(year<=a&&year>=d)) {
        return 0;
    }
    if((day<c||day>f)&&(month<b||month>e)&&(year<=a&&year>=d)) {
        return 0;
    }
    if(month==0||day==0||year==0) {
        return 0;
    }
    if(month>13) {
        return 0;
    }
    if(day>=32) {
        return 0;
    }
    if(month==2) {
        if(day>28&&(!runnian(year))) {
            return 0;
        }
        if(day>29&&(runnian(year))) {
            return 0;
        }
        return 1;
    } else {
        if(day>31&&judge(month)) {
            return 0;
        }
        if(day>30&&!judge(month)) {
            return 0;
        }
        return 1;
    }   
}
int main() {
    string n,m;
    cin>>n>>m;
    a = atoi(n.substr(0,4).c_str());
    b = atoi(n.substr(4,2).c_str());
    c = atoi(n.substr(6,2).c_str());
    d = atoi(m.substr(0,4).c_str());
    e = atoi(m.substr(4,2).c_str());
    f = atoi(m.substr(6,2).c_str());
    int year = a;
    int month = b;
    int day = c;
    int ans = 0;
    for(int i = year;i<=d;++i) {
        int o,p,q;
        o = year;
        string a;
        stringstream ss;
        ss<<year;
        ss>>a;
        char b[101010];
        int len = 0;
        for(int i = a.length()-1;i>=0;--i) {
            b[len] = a[i];
            len++;
        }
        string c(b);
        p = atoi(c.substr(0,2).c_str());
        q = atoi(c.substr(2,2).c_str());
        year++;
        if(in(o,p,q)) {
            ans++;
        }
    }
    cout<<ans<<endl;
}

by gongcharlie @ 2019-08-16 12:06:46

#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
int m[13]={31,28,31,30,31,30,31,31,30,31,30,31};
bool hv(int x){
    int a[10]={x/10000000,x/1000000%10,x/100000%10,x/10000%10,x/1000%10,x/100%10,x/10%10,x%10};
//  for(int i=0;i<8;i++) printf("%d ",a[i]);
    if(a[0]==a[7]&&a[1]==a[6]&&a[2]==a[5]&&a[3]==a[4]) return true;
    return false;
}
bool rq(int x){
    m[1]=28;
    int day=x%100;
    int month=x%10000/100;
    int year=x/10000;
    if(day>31) return false;
    if(month>12) return false;
    bool flag=false;
    int a=year%4;
    int b=year%100;
    int c=year%400;
    if(a==0){
        if(b!=0) m[1]=29;
        if(b==0&&c==0) m[1]=29;
    }
    if(m[month-1]<day) return false;
    return true;
}
int main()
{
    int i,j,n,m,sum=0;
    scanf("%d %d",&n,&m);
    for(int i=n;i<=m;i++)
    {
    //  cout<<"i:"<<i<<":";
        if(hv(i)==true&&rq(i)==true) sum++;
    //  cout<<endl;
        int day=i%100;
        if(day>31) i+=68;
    }
    printf("%d",sum);
    return 0;
}

@Taki


by littlefrog @ 2019-08-16 13:12:12


|