int 类型取出各位的方法:
“ % ”除掉前面的," % "后面的时剩下的几位;
“ / ”除掉后面的 用来取一个int整数的各个位置
eg:对于数abcde
a=abcde/10000
b=(abcde/1000)%10
c=(abcde/100)%10
d=(abcde/10)%10
e=(abcde/1)%10
#include<iostream>
#include<map>
#include<math.h>
using namespace std;
//“% ”除掉前面的,%后面的时剩下的几位“/ ”除掉后面的 用来取一个int整数的各个位置
int months[20]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool checkSati(int date)
{
int year=date/10000;
int month=date%10000/100;
int day=date%100;
if(month>12||month<1) return false;
if(months[month]<day&&month!=2) return false;
if(month==2)
{
if((year%4==0&&year%100!=0)||year%400==0)
{
if(day>29)
return false;
}
else
{
if(day>28)
return false;
}
}
return true;
}
bool check1(int date)
{
int a,b,c,d,e,f,g,h;
a=date/10000000;
b=(date/1000000)%10;
c=(date/100000)%10;
d=(date/10000)%10;
e=(date/1000)%10;
f=(date/100)%10;
g=(date/10)%10;
h=(date/1)%10;
if(a==h&&b==g&&c==f&&d==e)
{
return true;
}
return false;
}
bool check2(int date)
{
int a,b,c,d,e,f,g,h;
a=date/10000000;
b=(date/1000000)%10;
c=(date/100000)%10;
d=(date/10000)%10;
e=(date/1000)%10;
f=(date/100)%10;
g=(date/10)%10;
h=(date/1)%10;
if(a==h&&a==c&&c==f&&b==g&&b==d&&d==e)
{
return true;
}
return false;
}
int main()
{
int date,flag=0;
cin>>date;
for(int i=date+1;;i++)
{
if(checkSati(i))
{
if(!flag&&check1(i))
{
cout<<i<<endl;
flag=1;
}
if(check2(i))
{
cout<<i<<endl;
return 0;
}
}
}
}