- 生日日数
- 2025-03-29 18:09:40 @
这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?这题怎么写?大佬们能不能用简单一点的方法,超急!超急!超急!超急!超急!
2 条评论
-
winterini LV 4 @ 2025-04-10 01:07:13
本题基础题
题目要求输出生日后10000日期
那就纯模拟了,肯定不会超时
就O(1) 根本不会超
只需要注意大小月,闰年判断即可
可以用 switch case 完成即可
代码变量命名全部是直接汉语翻译过来的,每个函数可以翻译我的定义名来看看是啥意思注意处理月份和年份的变化
每次增加一天时,检查当前月份的天数是否已经超出。如果是,则月份加1,天数重置为1。如果月份超过12,则年份加1,月份重置为1。
闰年判断:判断当前年份是否为闰年,以确定二月份的天数(闰年29天,平年28天)。
闰年的判断规则:能被4整除但不能被100整除,或者能被400整除的年份是闰年。
#include <iostream> using namespace std; bool isLeapYear(int year) { if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { return true; } return false; } int getDaysInMonth(int year, int month) { switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: return isLeapYear(year) ? 29 : 28; default: return 0; } } void addDays(int &year, int &month, int &day, int daysToAdd) { for (int i = 0; i < daysToAdd; ++i) { day++; int daysInMonth = getDaysInMonth(year, month); if (day > daysInMonth) { day = 1; month++; if (month > 12) { month = 1; year++; } } } } int main() { int YY, MM, DD; cin >> YY >> MM >> DD; addDays(YY, MM, DD, 10000); cout << YY << "-" << MM << "-" << DD << endl; return 0; }
-
2025-03-29 18:19:11@
超急!
- 1