回文1

<div class="cnblogs_Highlighter"><pre class="brush:csharp;gutter:true;"> 

 

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

 

//思路:用了两个while循环,分别判断出回文和ABABBABA,并输出

用三个for循环嵌套,来判断是否符合条件

 


bool bbb(int i)          //判断是否为ABABBABA
{
string str=to_string(i);
int j;

if(str[0]==str[7]&&str[0]==str[2]&&str[2]==str[5]&&str[3]==str[1]&&str[3]==str[4]&&str[3]==str[6])
{
return false;
}
return true;
}
bool check(int i)          //判断是否为回文
{
string str=to_string(i);
int j;

if(str[0]==str[7]&&str[1]==str[6]&&str[2]==str[5]&&str[3]==str[4])
{
return false;
}
return true;
}
bool ccc(int i)      //判断是否为闰年
{
if(i%4==0||i%100==0)
return false;

return true;
}

int main()
{
int i=0,j,k,m,n;
int w,e;

bool bns=true;
scanf("%d",&n);
int y=n/10000;        //年
int x=n%10000/100;      //月
int z=n%100;          //日
while(1)
{
for(j=x;j<=12;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
{
for(k=z+1;k<=31;k++)
{
m=y*10000+j*100+k;


if(check(m)==false)
{
bns=false;
w=j;e=k;
break;

}
}
if(bns==false)
break;
}
if(j==4||j==6||j==9||j==11)
{
for(k=z+1;k<=30;k++)
{


m=y*10000+j*100+k;
if(check(m)==false)
{
bns=false;
w=j;e=k;
break;

}
}
if(bns==false)
break;
}
if(j==2)
{
if(ccc(y)==false)
{
for(k=z+1;k<=28;k++)
{

m=y*10000+j*100+k;
if(check(m)==false)
{
bns=false;
w=j;e=k;
break;

}
}
if(bns==false)
break;
}
else
{
for(k=z+1;k<=29;k++)
{

m=y*10000+j*100+k;

if(check(m)==false)
{
bns=false;
w=j;e=k;
break;

}
}
if(bns==false)
break;
}
}
}

if(bns==false)
break;
y++;
}
printf("%d%02d%02d",y,w,e);
printf("\n");
bns=true;
while(1)
{
for(j=x;j<=12;j++)
{
if(j==1||j==3||j==5||j==7||j==8||j==10||j==12)
{
for(k=z+1;k<=31;k++)
{
m=y*10000+j*100+k;


if(bbb(m)==false)
{
bns=false;
w=j;e=k;
break;

}
}
if(bns==false)
break;
}
if(j==4||j==6||j==9||j==11)
{
for(k=z+1;k<=30;k++)
{


m=y*10000+j*100+k;
if(bbb(m)==false)
{
bns=false;
w=j;e=k;
break;

}
}
if(bns==false)
break;
}
if(j==2)
{
if(ccc(y)==false)
{
for(k=z+1;k<=28;k++)
{

m=y*10000+j*100+k;
if(bbb(m)==false)
{
bns=false;
w=j;e=k;
break;

}
}
if(bns==false)
break;
}
else
{
for(k=z+1;k<=29;k++)
{

m=y*10000+j*100+k;

if(bbb(m)==false)
{
bns=false;
w=j;e=k;
break;

}
}
if(bns==false)
break;
}
}
}

if(bns==false)
break;
y++;
}
printf("%d%02d%02d",y,w,e);

return 0;
}

 

</pre></div> 

posted @ 2022-03-24 21:00  ghgfdsf  阅读(59)  评论(0)    收藏  举报