尘客


私信TA

用户名:3063757146

访问量:223

签 名:

等  级
排  名 13906
经  验 849
参赛次数 2
文章发表 1
年  龄 19
在职情况 学生
学  校 青岛大学
专  业 计算机类

  自我简介:

解题思路:枚举每一天判断这一天是否符合要求

注意事项:

10000101 ≤ N ≤ 89991231

我们的判断就得是八位数的最大 年份最大为9999


参考代码:

#include<bits/stdc++.h>

using namespace std;

#define INF 998244353

const int MAX=2e5+10;

bool ishuiwen(int day)

{//先将day存到s中,再用双指针判断s是否回文 

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()

{/*20200202

20211202

21211212

*/

int time;

cin>>time;

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

    int res1;

    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)

            {//闰年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(ishuiwen(day))

            {          

            if(day<=time)continue;

            if(flag==0)

            res1=day;

             flag=1;

             if(isAB(day))

             {

             cout<<res1<<endl<<day<<endl;

             return 0;

             }

             }

            }

        }

    }

return 0;

}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区