一道很简单的题,但是不知道哪里错了。。。

P2010 [NOIP2016 普及组] 回文日期

pencil @ 2020-10-09 22:44:49

RT

#include<bits/stdc++.h>
using namespace std;
int main() {
    char a[10];
    int y1,d1,m1,y2,d2,m2,dt[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31},r,ans=0;
    cin>>a;
    y1=a[3]-'0'+(a[2]-'0')*10+(a[1]-'0')*100+(a[0]-'0')*1000;
    m1=(a[5]-'0')+(a[4]-'0')*10;
    d1=(a[7]-'0')+(a[6]-'0')*10;
    cin>>a;
    y2=a[3]-'0'+(a[2]-'0')*10+(a[1]-'0')*100+(a[0]-'0')*1000;
    m2=(a[5]-'0')+(a[4]-'0')*10;
    d2=(a[7]-'0')+(a[6]-'0')*10;
    for(int i=1; i<=12; i++) { //month
        for(int i2=1; i2<=dt[i]; i2++) { //day
            r=(i/10)+(i%10)*10+(i2/10)*100+(i2%10)*1000;
            if(y1<r&&r<y2) ans++;
            if(y1==r) { //toyear
                if(y1<i)ans++;
                if(y1==i&&d1<i2)ans++;
            } else if(y2==r) {
                if(y1>i)ans++;
                if(y1==i&&d1>i2)ans++;
            }
        }
    }
    if(y1<9200&&y2>9200||(y1==9200&&m1>2&&(y2<9200||m2<2)))ans++;
    cout<<ans;
    return 0;
}

|