洛谷 \(P2010\)
大体题意
给定两个日期,然后让你求这两个日期中的日期有没有一个回文日期.
分析
首先对于\(60%\)的数据\(data1 == data2\).
我们可以直接输出1或者输出0.每一个可以得到30分的高分.
我们直接暴力枚举的话应该是不会过(我没试过).
所以我们要用一种比较玄学的方法来做.
解题思路
我们可以枚举每一个月份,然后枚举每一个月份的日期.
然后把每一个得到的日期反过来,然后再乘以\(10000\) 加上原来没有翻过来的数.
然后把得到的那个数再看看是不是在\(data1\) 和\(data2\) 的区间之内,
如果在那么\(ans\)就加一了鸭.
好料,此题结束.
code
#include <bits/stdc++.h> #define N 100010 #define M 1010 using namespace std; int yue[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int data1, data2; int read() { int s = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f |= (ch == '-'), ch = getchar(); while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar(); return f ? -s : s; } int main() { int ans = 0; data1 = read(), data2 = read(); for (int i = 1; i <= 12; i++) { for (int j = 1; j <= yue[i]; j++) { int day = i * 100 + j; day += j % 10 * 10000000; day += j / 10 % 10 * 1000000; day += i % 10 * 100000; day += i / 10 % 10 * 10000; if (data1 <= day && day <= data2) ans++; } } cout << ans; }