?》?

P2010 [NOIP2016 普及组] 回文日期

weiyi8910 @ 2024-10-11 15:27:54

#include <bits/stdc++.h>
using namespace std;

bool hw(long long a[1001]) {
    for (int i = 0; i <  8; i++) {
        if (a[i] != a[8 - 1 - i]) {
            return 0;
        }
    }
    return 1;
}

long long s[1001] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
    long long c[1001];
    string  a, b, d;
    long long hhh, www, jjj, yyy, xxx, sss, ans = 0;
    cin >> a >> b;
    hhh = int(b[0] - '0') * 1000 + int(b[1] - '0') * 100 + int(b[2] - '0') * 10 + int(b[3] - '0');
    www = int(a[0] - '0') * 1000 + int(a[1] - '0') * 100 + int(a[2] - '0') * 10 + int(a[3] - '0');

    /*jjj=int(a[4]-'0')*10+int(a[5]-'0');
    yyy=int(b[4]-'0')*10+int(b[5]-'0');
    xxx=int(a[6]-'0')*10+int(a[7]-'0');
    sss=int(b[6]-'0')*10+int(b[7]-'0');*/
    for (long long i = www; i <= hhh; i++) {
        c[0] = i / 1000;
        c[1] = i % 1000 / 100;
        c[2] = i % 1000 % 100 / 10;
        c[3] = i % 10;
        c[7] = i / 1000;
        c[6] = i % 1000 / 100;
        c[5] = i % 1000 % 100 / 10;
        c[4] = i % 10;

        if (c[4] * 10 + c[5] <= 12 && c[4] * 10 + c[5] >= 1) {
            if (c[6] * 10 + c[7] <= s[c[6]  * 10 + c[7]]
                    && c[6]  * 10 + c[7] >= 1) {
                if (hw(c)) {
                    ans++;
                }
            }
        }
    }
    cout << ans;
    return 0;
}

by Transparent_fish @ 2024-10-11 15:28:43

qp


|