#include<bits/stdc++.h>
using namespace std;
bool check(int a)//判断日期
{ int nian,yue,ri; int yues[13]={0,31,30,31,30,31,30,31,31,30,31,30,31};
nian=a/10000;
yue=a/100%100;
ri=a%100;
if(yue==0||yue>12||ri==0)return false;
if(yue!=2&&ri>yues[yue])return false;
if(yue==2)
{
if((nian%4==0&&nian%100!=0)||nian%400==0)
{
if(ri>29)return false;
}
else if(ri>28)return false;
}
return true;
}
bool huiwen1(int a)
{
string s;
s=to_string(a);
for(int i=0,j=7;i<=3;i++,j--)
{
if(s[i]!=s[j])return false;
}
return true;
}
bool huiwen2(int a)
{
string s;
s=to_string(a);
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()
{
int n;cin>>n;
int x=0,y=0;
while(1)
{n++;
if(check(n))
{
if(huiwen1(n)&&x==0)x=n;
if(huiwen2(n)&&y==0)y=n;
}
if(x!=0&&y!=0)break;
}
cout<<x<<endl<<y;
}
蓝桥杯—回文日期
最新推荐文章于 2024-07-12 18:02:43 发布