题目描述
c++ 暴力枚举爆破
C++ 代码
#include<bits/stdc++.h>
using namespace std;
string ans1,ans2;
bool check3(int a){
int month =(a%10000)/100;
int day = a%100;
if(month>12 || day > 31|| month == 0 || day == 0) return false;
int year = a/10000;
if(year % 400 == 0 || (year % 4 ==0 && year % 100 !=0)){
if(month==2 && day > 29) return false;
}else{
if(month==2 && day > 28) return false;
}
if(month == 4 || month == 6 || month == 9 || month == 11 ){
if(day >30) return false;
}
return true;
}
bool check1(int a){
string s = to_string(a);
if (s == string(s.rbegin(),s.rend())){
ans1 = s;
return true;
}
return false;
}
bool check2(int a){
string s = to_string(a);
if (s[0]== s[2] && s[2] == s[5] && s[5] ==s[7] && s[1]== s[3] && s[3] == s[4] && s[4] ==s[6] && s[0]!=s[1]){
ans2 = s;
return true;
}
return false;
}
int main(){
int n,t;
cin>>n;
int f1 = 1,f2 = 1;
while(f1 || f2){
n++;
if(!check3(n)) continue;
if(f1) {
if(check1(n)) f1 = 0;
}
if(f2) {
if(check2(n)) f2 = 0;
}
}
cout<<ans1<<endl<<ans2;
return 0;
}