AcWing 2867. 回文日期
原题链接
简单
作者:
S_14
,
2022-02-24 11:34:45
,
所有人可见
,
阅读 161
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int D[13]={0,31,29,31,20,31,20,31,31,20,31,20,31};
bool judge(int year){
return year%400==0 || year%4==0 && year%100!=0;
}
// 判断是否满足ABABBABA
bool ju(string s){
if(s[0] == s[2] && s[0]==s[5] && s[0] ==s[7] && s[1]==s[3] &&s[1] ==s[4] && s[1]==s[6] && s[0]!=s[1]){
return true;
}
return false;
}
int main(){
string str,an1="",an2="";
cin>>str;
for(int i=stoi(str.substr(0,4));an1==""||an2=="";i++){
string s1=to_string(i),s2=s1;
reverse(s2.begin(),s2.end());
s1+=s2;
if(s1<=str){
continue;
}
int year=stoi(s1.substr(0,4));
int month=stoi(s1.substr(4,2));
int day=stoi(s1.substr(6,2));
if(judge(year)){
D[2]=29;
}else
D[2]=28;
if(month>12 || month<1){
continue;
}
if(day >D[month] || day<1){
continue;
}
if(an1==""){
an1=s1;
}
if(an2=="" && ju(s1)){
an2=s1;
}
}
cout<<an1<<endl<<an2;
return 0;
}