年满12周岁

题目描述

输入一个学生的出生年、月、日,判断该同学到 2018 年 7 月 18 日是否年满 12 周岁?

如果是 2006 年 7月 18 日出生的,那么正好满 12 周岁。

输入格式

三个整数 y、m、d(假设 y、m、d 均为有效合理的数据),表示年、月、日,数据之间用 1 个空格隔开。

输出格式

结果为 Yes 或 No,表示是否年满 12 周岁。

样例 #1

样例输入 #1

2001 8 1

样例输出 #1

Yes

提示

注意字母的大小写

C++中,为了判断一个人是否在2022年10月28日满18周岁,首先你需要获取用户输入的出生日期(年、月、日)。然后你可以按照以下步骤进行计算: 1. 获取用户的出生年份、月份和日期。 ```cpp int birthYear, birthMonth, birthDay; cout << "请输入您的出生年份: "; cin >> birthYear; cout << "请输入您的出生月份(1-12): "; cin >> birthMonth; cout << "请输入您的出生日期: "; cin >> birthDay; ``` 2. 检查当前年份是否大于或等于出生年份,并且如果小于2022年,则检查当前月份加上剩余天数(考虑到闰年的情况),是否已经超过了18岁的总天数。 ```cpp bool isEighteen = false; // 当前年份和当前日期 int currentYear = 2022; int currentMonth = 10; int currentDay = 28; // 固定值 if (currentYear >= birthYear) { int daysUntilEighteen = 365 * (currentYear - birthYear); // 年龄差的天数 if (birthMonth > currentMonth || (birthMonth == currentMonth && birthDay <= currentDay)) { // 如果出生日期晚于或等于当前日期,计算今年剩下的天数并加到年龄差上 int remainingDaysInCurrentYear = 365 - (currentMonth * 30 + currentDay); if (isLeapYear(currentYear)) { // 判断是否为闰年 remainingDaysInCurrentYear += 1; // 闰年的二月多一天 } daysUntilEighteen += remainingDaysInCurrentYear; } if (daysUntilEighteen >= 18 * 365) { // 18岁相当于大约5475天 isEighteen = true; } } // 判断函数 bool isLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值