0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 13:56:26 +00:00

P2010 [NOIP2016 普及组] 回文日期

R69127852
This commit is contained in:
Baoshuo Ren 2022-02-11 22:21:22 +08:00
parent e39944305a
commit 0c63ada187
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
3 changed files with 41 additions and 0 deletions

35
Luogu/P2010/P2010.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
const int days[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct node {
int year, month, day;
} date1, date2;
using namespace std;
int ans;
std::string s1, s2;
int main() {
scanf("%4d%2d%2d", &date1.year, &date1.month, &date1.day);
scanf("%4d%2d%2d", &date2.year, &date2.month, &date2.day);
for (int yy = date1.year; yy <= date2.year; yy++) {
for (int mm = (yy == date1.year ? date1.month : 1);
mm <= (yy == date2.year ? date2.month : 12);
mm++) {
for (int dd = (yy == date1.year && mm == date1.month ? date1.day : 1);
dd <= (yy == date2.year && mm == date2.month ? date2.day : days[mm]);
dd++) {
s1 = s2 = std::to_string(yy * 10000 + mm * 100 + dd);
std::reverse(s2.begin(), s2.end());
if (s1 == s2) ans++;
}
}
}
printf("%d\n", ans);
return 0;
}

BIN
Luogu/P2010/data/P2010_9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P2010/data/P2010_9.out (Stored with Git LFS) Normal file

Binary file not shown.