C++ 代码
/*
****
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
01 02 03 04 05 06 07 08 09 10 11 12
360种左右:回文串
11种:ABABBABA
0101 0202 0303 0404 0505 0606 0707 0808 0909 1010 1212
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;
int date[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int trans(int x,int y){
string s1,s2,res,t;
stringstream stream1;
stream1 << x;
stream1 >> s1;
stringstream stream2;
stream2 << y;
stream2 >> s2;
if(x/10==0) s1 = "0"+s1;
if(y/10==0) s2 = "0"+s2;
res = s1 + s2;
t = res;
reverse(t.begin(),t.end());
res = t + res;
stringstream stream3;
stream3 << res;
int ans;
stream3 >> ans;
return ans;
}
bool check(int x){
int month = 0,day = 0,year = 0;
string str;
stringstream stream;
stream << x;
stream >> str;
month = (str[4]-'0')*10 + (str[5]-'0');
day = (str[6]-'0')*10 + (str[7]-'0');
year = (str[0]-'0')*1000 + (str[1]-'0')*100 + (str[2]-'0')*10 + (str[3]-'0');
if(month==2){
if(year%400==0 || (year%4==0&&year%100!=0)){
if(day>date[month-1]+1) return false;
}else{
if(day>date[month-1]) return false;
}
}else{
if(day>date[month-1]) return false;
}
return true;
}
int main()
{
int n;
cin >> n;
vector<int> v1,v2;
// trans(1,2);
for(int i=1;i<=12;i++){
for(int j=1;j<=31;j++){
v1.push_back(trans(i,j));
}
}
sort(v1.begin(),v1.end());
for(int i=1;i<=12;i++){
if(i==11) continue;
v2.push_back(trans(i,i));
}
sort(v2.begin(),v2.end());
int ans1,ans2;
for(int i=0;i<v1.size();i++){
// cout << v1[i] << endl;
if(check(v1[i]) && v1[i]>n){
ans1 = v1[i];
break;
}
}
for(int i=0;i<v2.size();i++){
if(v2[i]>n){
ans2 = v2[i];
break;
}
}
cout << ans1 << endl << ans2 << endl;
return 0;
}