AcWing 2867. 回文日期
原题链接
简单
作者:
现代修士o_O
,
2021-03-29 15:40:47
,
所有人可见
,
阅读 3
C++ 代码
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int months[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool judge(int fi){
int year = fi/10000;
int month = fi/100%100;
int day = fi%100;
if(month<=0||month>12) return false;
if(day==0 || ( month!=2&&day>months[month] ) ) return false;
if(month == 2){
int leap=0;
if( (year%4==0 && year%100!=0) || year%400==0) leap=1;
if(day > 28+leap) return false;
}
return true;
}
int main(){
int n,ans1=0,ans2=0;
cin >> n;
for(int i=n+1; i<=899912310; i++){
if(!judge(i)) continue;
int temp =i;
int fi =0;//翻转
while(temp){
int t = temp % 10;
fi = fi*10 + t;
temp /= 10;
}
if(i==fi){
if(ans1==0) ans1 = i;
if(i%10==i/100%10 && i/10%10==i/1000%10 && i%10!=i/10%10){
ans2=i;
break;
}
}
}
cout<<ans1<<endl<<ans2<<endl;
return 0;
}