本文主要是介绍洛谷 [蓝桥杯 2020 省 AB2] 回文日期,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include <iostream>
using namespace std;int d[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};bool is_valid(int i){int year = i / 10000;i = i % 10000;int month = i / 100;i = i % 100;int day = i;if ( (year%4 == 0 && year%100!= 0) || (year%400==0) ){ //闰年 if ( month==2 && day > 29){return false;}}if (month > 13 || month == 0){return false;}if(day > d[month] || day == 0){return false;}return true;
}
bool is_hui(int i){int year = i / 10000;i = i % 10000;int month = i / 100;i = i % 100;int day = i;int i_1 = month % 10;int i_2 = month / 10;int sum_1 = i_1*10 + i_2;int i_3 = day % 10;int i_4 = day / 10;int sum_2 = i_3*10 + i_4;if (sum_1 + sum_2*100 == year){return true;}return false;
}
bool is_ab(int i){int i_1 = i % 10;i = i / 10;int i_2 = i % 10;i = i / 10;int i_3 = i % 10;i = i / 10;int i_4 = i % 10;i = i / 10;int i_5 = i % 10;i = i / 10;int i_6 = i % 10;i = i / 10;int i_7 = i % 10;i = i / 10;int i_8 = i;if ( (i_1 == i_3) && (i_3 == i_6) && (i_6 == i_8) ){if ( (i_2 == i_4) && (i_4 == i_5) && (i_5 == i_7) ){return true;}}return false;
}
int main (){int n;cin>>n;int flag = 0;for (int i = n+1;i < 99999999;i++){if(is_valid(i) && is_hui(i)){cout<<i<<endl;break;}}for (int i = n+1;i < 99999999;i++){if(is_valid(i) && is_ab(i)){cout<<i;break;}}return 0;
}
这篇关于洛谷 [蓝桥杯 2020 省 AB2] 回文日期的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!