这种题得多细心呀,看到不通过才知道debug,这到比赛咋行哦
#include<bits/stdc++.h>
using namespace std;
int tmp,l,r,cnt;
bool check(int n)
{
int y=n/10000;
int m=n/100%100;
int d=n%100;
//cout<<y<<' '<<m<<' '<<d<<endl;
int dd[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(m>12||m==0) return false;
if(d==0||d>31) return false;
if(m!=2&&d>dd[m]) return false;
if(m==2)
{
if((y%4==0&&y%100!=0)||(y%400==0))
{
if(d>29) return false;
}
else
{
if(d>28) return false;
}
}
return true;
}
bool check2(int n)
{
int y=n/10000;
int ll=y/100;
int rr=y%100;
int lll=ll/10;
int rrr=ll%10;
if(ll==rr&&lll!=rrr) return true;
else return false;
}
int var(int n)
{
int a,b,c,d;
a=n/1000;
b=n/100%10;
c=n/10%10;
d=n%10;
return a+b*10+c*100+d*1000;
}
int main()
{
cin>>tmp;
r=tmp%10000;
l=tmp/10000;
for(int i=l;i<=9999;i++)
{
int n=i*10000+var(i);
if(n<=tmp) continue;
if(check(n))
{
if(cnt==0)
{cout<<n<<endl;cnt++;}
if(check2(n))
{cout<<n<<endl;break;}
}
}
return 0;
}