60分求助!!!

P2010 [NOIP2016 普及组] 回文日期

wendi_babasituo @ 2023-09-24 14:34:24

#include<iostream>
using namespace std;
int main() {
    int date1, date2, year1, year2, day1, sum = 0;
    cin >> date1 >> date2;
    year1 = date1 / 10000;
    year1 = date2 / 10000;
    while (year1 <= year2) {
        day1 = year1 % 10 * 1000 + year1 / 10 % 10 * 100 + year1 / 100 % 10 * 10 + year1 / 1000;
        if(day1>date2%10000||day1<date1%10000){
            break;
        }
        if (day1 / 100 <= 12 && day1 / 100 > 0) {
            if (day1 / 100 == 4 || day1 / 100 == 6 || day1 / 100 == 9 || day1 / 100 == 11) {
                if (day1 % 100 <= 30 && day1 % 100 > 0) {
                    sum++;
                    break;
                }
            }
            if (day1 / 100 == 2) {
                if (day1 % 100 <= 29 && day1 % 100 > 0) {
                    sum++;
                    break;
                }
            } else {
                if (day1 % 100 <= 31 && day1 % 100 > 0) {
                    sum++;
                    break;
                }
            }
        }
        year1 += 1;
    }
    cout << sum;
    return 0;
}

by 17192179788x @ 2023-09-24 20:31:12

第7行你看看,是year2吧


|