题目
代码
#include <bits/stdc++.h>
using namespace std;
int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string done1 = "", done2 = "";
bool is_run(int y, int m)
{if(m != 2) return false;if (y % 400 == 0)return true;if (y % 100 && y % 4 == 0)return true;return false;
}
void Do(int y, int m, int d, int mode)
{string s = to_string(y);char a = s[0], b = s[1];if(mode == 2 && a == b) return;s += to_string(m / 10);s += to_string(m % 10);s += to_string(d / 10);s += to_string(d % 10);int l = 0, r = s.size() - 1;while (l < r){if (mode == 2 && l){if(s[l] != a && s[l] != b) return;else if(s[l] == a && s[l-1] != b) return;else if(s[l] == b && s[l-1] != a) return;}if (s[l++] != s[r--])return;}if (mode == 1)done1 = s;else if (mode == 2)done2 = s;
}
int main()
{string s;cin >> s;int y, m, d;string sy = s.substr(0, 4);y = stoi(sy);string sm = s.substr(4, 2);m = stoi(sm);string sd = s.substr(6, 2);d = stoi(sd);do{d++;if (d > month[m] + is_run(y, m)){d = 1;m++;}if (m > 12){m = 1;y++;}if (done1 == "")Do(y, m, d, 1);if (done2 == "")Do(y, m, d, 2);if (done1 != "" && done2 != "")break;}while(1);cout << done1 << '\n' << done2;
}