有没有佬帮看看为什么会WA三个点呢?

P2010 [NOIP2016 普及组] 回文日期

tachikoma @ 2024-04-13 23:29:05

#include<iostream>
#include<string>
using namespace std;
int fr, bk;
int month, day;
int bDay, bMonth;
int isRun(int a) {
    bool case1 = a * 1.0 / 4 > 0 && a % 100!=0;
    bool case2 = a * 1.0 / 400 == 0;
    if (case1 ^case2) {
        return 1;
    }
    else
        return 0;

}
int getMonth(int a) {
    return a / 10000 % 100;

}
int getDay(int a) {
    return a / 1000000;
}
int getYear(int a) {
    return a / 10000;
}
int getbDay(int a) {
    int day = getDay(a);
    day = day / 10 + day % 10 * 10;
    return day;
}
int getbMonth(int a) {
    int month = getMonth(a);
    month = month / 10 + month % 10 * 10;
    return month;
}
int newDay(int a) {
    int bd = getbDay(a);
    int bm = getbMonth(a);
    return a / 10000 * 10000 + bm * 100 + bd;

}
int main() {
    cin >> fr >> bk;
    int cnt = 0;
    while (fr <= bk) {
        bMonth = getbMonth(fr);
        bDay = getbDay(fr);
        if (0 < bMonth &&bMonth < 13 && bDay<32&&0 < bDay) {
            if (bMonth == 1 || bMonth == 3 || bMonth == 5 || bMonth == 7 || bMonth == 8 || bMonth == 10 || bMonth == 12) {
                if (newDay(fr) >= fr && newDay(fr) <= bk)
                    cnt++;

            }else if(bMonth==2){
                if (bDay < 29) {
                    if (newDay(fr) >= fr && newDay(fr) <= bk)
                        cnt++;
                }else if (bDay == 29) {
                    if (isRun(getYear(fr))) {
                        if (newDay(fr) >= fr && newDay(fr) <= bk)
                            cnt++;
                    }
                }

            }
            else {
                if (bDay < 31)
                    if (newDay(fr) >= fr && newDay(fr) <= bk)
                        cnt++;

            }

        }
        fr +=10000;
    }
    cout << cnt << endl;

    return 0;
}

|