社区讨论
100pts求调(闭关)
P2010[NOIP 2016 普及组] 回文日期参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mhqm3fiz
- 此快照首次捕获于
- 2025/11/09 02:22 3 个月前
- 此快照最后确认于
- 2025/11/16 14:04 3 个月前
CPP
#include <bits/stdc++.h>
using namespace std;
long long a, b;
long long n, cnt, y, r, n1, y2, r1, m[50] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string arr;
bool hw(string wsb) {
for (int i = 0, j = wsb.size() - 1; i <= j; i++, j--) {
if (wsb[i] != wsb[j]) {
return 0;
}
}
return 1;
}
int main() {
cin >> a >> b;
n = a / 10000;
n1 = b / 10000;
y = a / 100 % 100;
y2 = b / 100 % 100;
r = a % 100;
r1 = b % 100;
cnt = 0;
for (int i = n; i <= n1; i++) {
if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)) {
m[2] = 29;
} else {
m[2] = 28;
}
for (int j = 1; j <= 12; j++) {
for (int k = 1; k <= m[j]; k++) {
string year, month, day, arr;
if (i < 10) year = "000" + to_string(i);
else if (i < 100) year = "00" + to_string(i);
else if (i < 1000) year = "0" + to_string(i);
else year = to_string(i);
if (j < 10) month = "0" + to_string(j);
else month = to_string(j);
if (k < 10) day = "0" + to_string(k);
else day = to_string(k);
arr = year + month + day;
if (hw(arr)) {
cnt++;
}
}
}
}
cout << cnt << endl;
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...