题目2571:蓝桥杯2020年第十一届省赛真题-回文日期

#include<iostream>

using namespace std;

bool ispre(int day){

string s;

while(day){

s+=day%10+'0';

day/=10;

}

for(int i=0,j=7;i<j;i++,j--){

if(s[i]!=s[j]){

return false;

}

}

return true;

}

bool isAB(int day){

string s;

while(day){

s+=day%10+'0';

day/=10;

}

if(s[0]==s[2]&&s[1]==s[3]){

return true;

}

return false;

}

int main(){

int time;

cin>>time;

int monthdays[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int res;

int flag=0;

for(int year=1000;year<=9999;year++){

//遍历每一天,判断是否为回文数和AB

if(year*10000+10000<time){

continue;

}

for(int month=1;month<=12;month++){

int days=monthdays[month];

if(month==2){

//闰年二月加一天

if((year%400==0)||(year%4==0&&year%100!=0)){//闰年判断

days++;

}

}

for(int i=1;i<=days;i++){

int day=i+month*100+year*10000;

if(ispre(day)){

if(day<=time){

continue;

}

if(flag==0){

res=day;

flag=1;

}

if(isAB(day)){

cout<<res<<endl<<day<<endl;

return 0;

}

}

}

}

}

return 0;

}

相关推荐
老四啊laosi2 小时前
[C++进阶] 24. 哈希表封装unordered_map && unordered_set
c++·哈希表·封装·unordered_map·unordered_set
2301_764441333 小时前
LISA时空跃迁分析,地理时空分析
数据结构·python·算法
东北洗浴王子讲AI3 小时前
GPT-5.4辅助算法设计与优化:从理论到实践的系统方法
人工智能·gpt·算法·chatgpt
妙为3 小时前
银河麒麟V4下编译Qt5.12.12源码
c++·qt·国产化·osg3.6.5·osgearth3.2·银河麒麟v4
Billlly3 小时前
ABC 453 个人题解
算法·题解·atcoder
玉树临风ives3 小时前
atcoder ABC 452 题解
数据结构·算法
feifeigo1234 小时前
基于马尔可夫随机场模型的SAR图像变化检测源码实现
算法
fengfuyao9854 小时前
基于STM32的4轴步进电机加减速控制工程源码(梯形加减速算法)
网络·stm32·算法
无敌昊哥战神5 小时前
深入理解 C 语言:巧妙利用“0地址”手写 offsetof 宏与内存对齐机制
c语言·数据结构·算法
小白菜又菜5 小时前
Leetcode 2075. Decode the Slanted Ciphertext
算法·leetcode·职场和发展