蓝桥杯--历届真题 回文日期【第十一届】【省赛】【B组】

试题 历届真题 回文日期【第十一届】【省赛】【B组】

提交此题   评测记录  

资源限制

时间限制:1.0s   内存限制:256.0MB

 哎话说好久没写过日期题了,回忆起刚学的时候被日期统治的恐惧了🤣🤣

#include<bits/stdc++.h>
using namespace std;

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

bool chack(int date)//判断日期是否合法
{
    int year=date/10000;
    int month=date%10000/100;
    int day=date%100;
    if(month<=0||month>12||day==0)return false;
    if(month!=2&&day>months[month])return false;
    if(month==2)//二月的日子需要特判一下闰年
    {
        if(year%400==0||(year%4==0&&year%100!=0))
        {
            if(day>29)return false;
        }
        else
        {
            if(day>28)return false;
        }
    }
    return true;
}


bool check1(int s)  //判断是否是回文日期
{
    int a=s/10000000;
    int b=(s/1000000)%10;
    int c=(s/100000)%10;
    int d=(s/10000)%10;
    int e=(s/1000)%10;
    int f=(s/100)%10;
    int g=(s/10)%10;
    int h=s%10;
    if(a==h&&b==g&&c==f&&d==e)
    {
        return true;
    }
    
    return false;
}

bool check2(int s)  //判断是否是回文日期
{
    int a=s/10000000;
    int b=(s/1000000)%10;
    int c=(s/100000)%10;
    int d=(s/10000)%10;
    int e=(s/1000)%10;
    int f=(s/100)%10;
    int g=(s/10)%10;
    int h=s%10;
    if(a==c&&c==f&&f==h&&b==d&&d==e&&e==g&&g!=h)
    return true;
    
    return false;
}


int main()
{
    int date,flag=0;
    cin>>date;
    for(int i=date+1;;i++)//从这天开始之后开始查找
    {
        if(chack(i))
        {
            
            if(check1(i)&&!flag)   
            {
                cout<<i<<endl;
                flag = 1;  //标记一下,避免多次输出
            }
            if(check2(i))  
            {
                cout<<i<<endl;
                return 0;
            }

        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值