You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// https://www.luogu.com.cn/problem/P2010
#include <bits/stdc++.h>
using namespace std;
//月份日期常数数组
int months[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//判断是不是闰年
bool LeapYear(int year) {
return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
}
//是不是回文字符串
bool isHW(string s) {
string t = s;
reverse(t.begin(), t.end());
return s == t;
}
int cnt;
int main() {
int st, ed;
cin >> st >> ed;
int y1 = st / 10000;
int y2 = ed / 10000;
//枚举年份
for (int i = y1; i <= y2; i++)
// 枚举月份
for (int j = 1; j <= 12; j++) {
//枚举日期
int day = months[j];
if (LeapYear(i) && j == 2) day = 29; //闰年二月份共29天
for (int k = 1; k <= day; k++) {
int s = i * 10000 + j * 100 + k;
//与范围字符串st,ed进行比较如果不在范围内continue
if (s < st || s > ed) continue; //日期字符串符合字典序
//判断是不是回文
char x[10];
sprintf(x, "%d", s);
if (isHW(x)) cnt++;
}
}
//输出
printf("%d\n", cnt);
return 0;
}