题目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;

}

相关推荐
我喜欢就喜欢1 小时前
基于离散余弦变换的感知哈希算法:原理、实现与工程实践
算法·哈希算法
尽兴-1 小时前
Redis7 底层数据结构解析
数据结构·数据库·缓存·redis7
2301_807367192 小时前
C++中的模板方法模式
开发语言·c++·算法
PhotonixBay2 小时前
共聚焦显微镜的结构组成与应用
人工智能·算法·机器学习
逆境不可逃2 小时前
LeetCode 热题 100 之 33. 搜索旋转排序数组 153. 寻找旋转排序数组中的最小值 4. 寻找两个正序数组的中位数
java·开发语言·数据结构·算法·leetcode·职场和发展
tankeven2 小时前
HJ137 乘之
c++·算法
add45a3 小时前
C++中的观察者模式
开发语言·c++·算法
进击的小头3 小时前
第13篇:基于伯德图的超前_滞后校正器深度设计
python·算法
leaves falling3 小时前
二分查找:迭代与递归实现全解析
数据结构·算法·leetcode