1283 回文日期 枚举 模拟 时间

jyssh / 2024-10-23 / 原文

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e3+10;

// 每个月的天数,2月暂时设为29天,后续会根据闰年和平年调整
int a[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
    int s1, s2, ans = 0;
    cin >> s1 >> s2; // 读取起始日期和终止日期

    // 遍历每个月
    for (int m = 1; m <= 12; m++) {
        // 遍历每一天
        for (int d = 1; d <= a[m]; d++) {
            // 生成回文日期
            int t = (d % 10) * 10000000 + (d / 10) * 1000000 + (m % 10) * 100000 + (m / 10) * 10000 + m * 100 + d;
            // 检查生成的回文日期是否在指定范围内
            if (t >= s1 && t <= s2)
                ans++;
        }
    }
    cout << ans; // 输出结果
    return 0;
}