牛客练习赛30
A-回文日期:题目链接
一个很麻烦的模拟题,不过值得一做(很锻炼代码能力)。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 2000 + 10;
int month[maxn] = { 0,1,2,3,4,5,6,7,8,9,10,11,12 };
int day[maxn] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
bool runnian(int x)
{
if (x % 4 == 0 && x % 100 != 0 || x % 400)
return true;
return false;
}
int main()
{
ios::sync_with_stdio(false);
string s, e;
int T;
cin >> T;
while (T--)
{
cin >> s >> e;
int sY = (s[0] - 48) * 1000 + (s[1] - 48) * 100 + (s[2] - 48) * 10 + (s[3] - 48);
int eY = (e[0] - 48) * 1000 + (e[1] - 48) * 100 + (e[2] - 48) * 10 + (e[3] - 48);
int sM = (s[5] - 48) * 10 + (s[6] - 48);
int eM = (e[5] - 48) * 10 + (e[6] - 48);
int sD = (s[8] - 48) * 10 + (s[8] - 48);
int eD = (e[8] - 48) * 10 + (e[8] - 48);
//cout << sY;
int ans = 0;
for (int i = sY; i<eY; i++) {
if (runnian(i))day[2] = 29;
else day[2] = 28;
for (int j = sM; j <= 12; j++) {
if (j == 12)sM = 1;
for (int k = sD; k <= day[month[j]]; k++) {
if (k == day[month[j]])sD = 1;
int t1 = (k % 10) * 1000;
int t2 = (k / 10) * 100;
int t3 = (j % 10) * 10;
int t4 = j / 10;
if (i == t1 + t2 + t3 + t4)ans++;
}
}
}
for (int i = 1; i<month[eM]; i++) {
for (int j = 1; j <= day[month[eM] - 1]; j++) {
int t1 = (j % 10) * 1000;
int t2 = (j / 10) * 100;
int t3 = (i % 10) * 10;
int t4 = i / 10;
if (t1 + t2 + t3 + t4 == eY)ans++;
}
}
int t3 = (month[eM] % 10) * 10;
int t4 = month[eM] / 10;
for (int i = 1; i <= eD; i++) {
int t1 = (i % 10) * 1000;
int t2 = (i / 10) * 100;
if (t1 + t2 + t3 + t4 == eY)ans++;
}
cout << ans << endl;
}
return 0;
}
C-小K的疑惑:题目链接
暂时没看懂这个dfs。。。有机会再补