[模板题]日期合法 原创

来源: 模板提
算法标签:日期
题目描述 判断日期是否合法
cpp代码
bool check(int date)
{
    int year=date/10000,month=date%10000/100,day=date%100;
    if(month>12||!month||!date)return false;
    else if(month!=2&&day>months[month])return false;
    else if(month==2)
        {
            int heap=year%400==0||year%100!=0&&year%4==0;
            if(day>28+heap)return false;
        }
    return true;
}
posted @ 2022-03-30 17:37  俺叫西西弗斯  阅读(0)  评论(0)    收藏  举报  来源