题目链接:精选项目课程_IT热门课程_蓝桥云课课程 - 蓝桥云课
题目解析:用i,j,k分别表示年月日,暴力循环加剪枝
代码:
//#define local
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool isrun(int y){
if((y%4==0)&&((y%100)!=0))
return true;
else if(y%400==0)
return true;
else
return false;
}
int a,b,c;
int main(){
#ifdef local
freopen("input1.txt","rb",stdin);
#endif
scanf("%d",&a);
bool o,t;
o=t=false;
for(int i=a/10000;;++i){
if((i%10<=1)&&(i%1000)/100<=3){
if(isrun(i))
day[2]=29;
else
day[2]=28;
int bj=(i==a/10000)?a%10000/100:1;
for(int j=bj;j<=12;++j){
if((i%10==j/10)&&(i%100/10==j%10)){
int bk=((i==a/10000)&&(j==a%10000/100))?a%100+1:1;
for(int k=bk;k<=day[j];++k){
if((i/100%10==k/10)&&(i/1000)==k%10){
if(!o){
o=true;
b=i*10000+j*100+k;
}
if(!t&&j==k){
t=true;
c=i*10000+j*100+k;
}
if(o&&t){
printf("%d\n%d",b,c);
return 0;
}
}
}
}
}
}
}
return 0;
}