吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1130|回复: 24
收起左侧

[C&C++ 原创] 输入1923~2023中的一天,给出下一天的日期

[复制链接]
prosperity 发表于 2024-3-23 14:51
[ 本帖最后由 苏紫方璇 于 2024-3-23 15:16 编辑 ]\n\n源码:
[C++] 纯文本查看 复制代码
#include<iostream>
using namespace std;
//判断是不是闰年,初始化x为0(不是闰年),x为1是闰年
int x=0;
//初始化默认天数为30
int t=30;
//定义年份(year),月份(month),天数(day)
int year,month,day;
//将31天数月份分别存放
int Month1[7]={1,3,5,7,8,10,12};
//将30天数月份分别存放
int Month2[4]={4,6,9,11};   

//天数加一函数
void NextDate(int year,int month,int day){
    cout<<"输出输入的日期为:";
    cout<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
   
    //是闰年
    if(x==1){
        if(month==2){
        //2月29日
            if(day+1==30){
                day=1;
                cout<<"输入日期后一天为:";
                 cout<<year<<"年"<<(month+1)<<"月"<<day<<"日"<<endl;
            }else{
                cout<<"输入日期后一天为:";
                cout<<year<<"年"<<month<<"月"<<(day+1)<<"日"<<endl;}
        }
        
        //此处通过t的值判断-->4,6,9,11月
    else if(t==30){
            if(day==30){
                day=1;
                cout<<"输入日期后一天为:";
                 cout<<year<<"年"<<(month+1)<<"月"<<day<<"日"<<endl;
            }else{
                //输入的日期天数不是30
                cout<<"输入日期后一天为:";
                cout<<year<<"年"<<month<<"月"<<(day+1)<<"日"<<endl;    }}
        
         //此处通过t的值判断-->1,3,5,7,8,10,12月
    else if(t==31){
            if(day==31){
                day=1;
                //12月31日
                if(month==12){
                    month=1;
                    cout<<"输入日期后一天为:";
                     cout<<(year+1)<<"年"<<month<<"月"<<day<<"日"<<endl;
                }else{
                    day=1;
                     cout<<"输入日期后一天为:";
                     cout<<year<<"年"<<(month+1)<<"月"<<day<<"日"<<endl;}
               
            }else{
                //输入的日期天数不是30
                cout<<"输入日期后一天为:";
                cout<<year<<"年"<<month<<"月"<<(day+1)<<"日"<<endl;    }
        }
    }else{
        //此时不为闰年x=0;
        //判断2月
        if(month==2){
            //2月28
            if(day+1==29){
                day=1;
                cout<<"输入日期后一天为:";
                 cout<<year<<"年"<<(month+1)<<"月"<<day<<"日"<<endl;
            }else{
                cout<<"输入日期后一天为:";
                cout<<year<<"年"<<month<<"月"<<(day+1)<<"日"<<endl;}
        }
        
        
    //此处通过t的值判断-->4,6,9,11月
    else if(t==30){
            if(day==30){
                day=1;
                cout<<"输入日期后一天为:";
                 cout<<year<<"年"<<(month+1)<<"月"<<day<<"日"<<endl;
            }else{
                //输入的日期天数不是30
                cout<<"输入日期后一天为:";
                cout<<year<<"年"<<month<<"月"<<(day+1)<<"日"<<endl;    }}
        
        
        else if(t==31){
            if(day==31){
                day=1;
                //12月31日
                if(month==12){
                    month=1;
                    cout<<"输入日期后一天为:";
                     cout<<(year+1)<<"年"<<month<<"月"<<day<<"日"<<endl;
                }else{
                    day=1;
                     cout<<"输入日期后一天为:";
                     cout<<year<<"年"<<(month+1)<<"月"<<day<<"日"<<endl;}
               
            }else{
                //输入的日期天数不是30
                cout<<"输入日期后一天为:";
                cout<<year<<"年"<<month<<"月"<<(day+1)<<"日"<<endl;    }}
    }
   
}
//主函数
int main(){
    int year,month,day;
    cout<<"请输入year,month,day"<<endl;
    cin>>year;
    cin>>month;
    cin>>day;
  
    if(year>=1923&&year<=2023){
        if((year%4==0 && year % 100 !=0)||(year % 400==0)){
            //cout<<"是闰年"<<endl;
            x=x+1;
            //判断输入月份是否合理
            if(month>=1&&month<=12){
                //判断闰年2月的天数输入合不合理
                if(month==2){
                    if(day>=1&&day<=29){
                            NextDate(year,month,day);
                    }else{
                            cout<<"输入天数不合理"<<endl;}
                }
               
               
                //判断天数为31的月份
                for(int i=0;i<7;i++){
                    if(month==Month1[i]){
                        t=t+1;//31
                        if(day>1&&day<=t){
                            NextDate(year,month,day);
                        } else{
                            cout<<"输入天数不合理"<<endl;}
                    }
                }
               
               
                    //判断天数为30的月份
                for(int i=0;i<4;i++){
                    if(month==Month2[i]){
                        if(day>=1&&day<=t){
                            NextDate(year,month,day);
                        }else{
                            cout<<"输入天数不合理"<<endl;}
                    }
                }
               
               
            }else{
                cout<<"输入月份不合理"<<endl;}
               
        }else{ //不是闰年
            if(month>=1&&month<=12){
                //判断不是闰年2月的天数输入合不合理
                if(month==2){
                    if(day>=1&&day<=28){
                            NextDate(year,month,day);
                    }else{
                            cout<<"输入天数不合理"<<endl;}
                }
               
               
               
                //判断天数为31的月份
                for(int i=0;i<7;i++){
                    if(month==Month1[i]){
                        t=t+1;//31
                        if(day>1&&day<=t){
                            NextDate(year,month,day);
                        } else{
                            cout<<"输入天数不合理"<<endl;}
                    }
                }
               
               
                    //判断天数为30的月份
                for(int i=0;i<4;i++){
                    if(month==Month2[i]){
                        if(day>1&&day<=t){
                            NextDate(year,month,day);
                        }else{
                            cout<<"输入天数不合理"<<endl;}
                    }
                }
               
               
            }else{
                cout<<"输入月份不合理"<<endl;}
        }
   
        
    }else{
        cout<<"输入年份不合理"<<endl;
    }
}
3d213ee01f00ff4d87c281870aa6696.png

免费评分

参与人数 1吾爱币 +5 热心值 +1 收起 理由
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

kapan000 发表于 2024-3-23 15:41
我看了标题,觉得奇怪,特意进来看了看
我竟然没有理解错?????

竟然还有这种没有任何意义的东西
哈哈哈
devilpanama 发表于 2024-3-23 15:35
ai写的
[Python] 纯文本查看 复制代码
def is_leap_year(year):
    # 判断年份是否是闰年
    return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)

def get_next_day(day, month, year):
    # 每个月的天数\n
    days_per_month = [31, 29 if is_leap_year(year) else 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    # 判断是否是月末\n
    if day < days_per_month[month - 1]:
        next_day = day + 1
        next_month = month
        next_year = year
    else:
        if month == 12:
            # 年末,进入下一年
            next_day = 1
            next_month = 1
            next_year = year + 1
        else:
            # 月末,进入下一月\n
            next_day = 1
            next_month = month + 1
            next_year = year

    return next_day, next_month, next_year

# 主程序
if __name__ == "__main__":
    input_date = input("请输入日期(格式:YYYY-MM-DD,范围1923-01-01至2023-12-31):")
    try:
        year, month, day = map(int, input_date.split('-'))
        # 检查日期是否在有效范围内
        if not (1923 <= year <= 2023):
            raise ValueError("年份超出范围")
        next_day, next_month, next_year = get_next_day(day, month, year)
        print(f"下一天是:{next_year}-{next_month:02d}-{next_day:02d}")
    except ValueError as e:
        print(f"输入错误:{e}")
Linsen1218 发表于 2024-3-23 15:21
ThemanRonin 发表于 2024-3-23 15:37
本帖最后由 ThemanRonin 于 2024-3-23 15:39 编辑

[C] 纯文本查看 复制代码
#include <stdio.h>
 
// 判断是否为闰年
int isLeapYear(int year) {
    return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
 
// 判断日期是否合法
int isValidDate(int year, int month, int day) {
    if (year < 0 || month < 1 || month > 12 || day < 1) {
        return 0;
    }
     
    int daysOfMonth[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    if (isLeapYear(year)) {
        daysOfMonth[2] = 29;
    }
     
    return day <= daysOfMonth[month];
}
 
// 计算下一天的日期
void nextDay(int *year, int *month, int *day) {
    int daysOfMonth[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    if (isLeapYear(*year)) {
        daysOfMonth[2] = 29;
    }
     
    (*day)++;
    if (*day > daysOfMonth[*month]) {
        (*month)++;
        *day = 1;
        if (*month > 12) {
            *year += 1;
            *month = 1;
        }
    }
}
 
int main() {
    int year, month, day;
    printf("请输入年月日(格式:年 月 日):");
    if (scanf("%d %d %d", &year, &month, &day) != 3 || !isValidDate(year, month, day)) {
        printf("输入日期不合法,请重新输入。\n");
        return 1;
    }
 
    printf("当前输入日期为:%d年%d月%d日\n", year, month, day);
    nextDay(&year, &month, &day);
    printf("到期后一天为:%d年%d月%d日\n", year, month, day);
 
    return 0;
}






鹏优CX-5 发表于 2024-3-23 15:43
用来做上面用呢?
sqzh 发表于 2024-3-23 15:46
匆匆忙忙,看了一下,没看明白
sai609 发表于 2024-3-23 16:32
day&#10133;1,print
c4647 发表于 2024-3-23 16:37
这有啥意义吗?
TIAOWUQINGYU 发表于 2024-3-23 16:56
没看懂练手的么
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 04:29

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表