文章
4
粉丝
22
获赞
37
访问
1.6k
参考题解有个小甲鱼的,使用了结构体
#include <bits/stdc++.h>
using namespace std;
struct Day {
int year;
int mon;
int date;
} day1, day2;
void Date(int input, Day &day) {
day.year = input / 10000; // 提取年份
day.mon = (input / 100) % 100; // 提取月份
day.date = input % 100; // 提取日期
}
bool LeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int daysMonth(int year, int month) {
int days[] = {31, 28, 31, 30, 31, 30 ,31, 31, 30, 31, 30, 31};
if (month == 2 && LeapYear(year)) {
return 29;
}
return days[month - 1];
}
int calculate(Day &day1, Day &day2) {
int cnt = 1; //应题目要求cnt初始为1
while (!(day1.year == day2.year && day1.mon == day2.mon && day1.date == day2.date)) {
day1.date++;
if (day1.date > daysMonth(day1.year, day1.mon)) {
day1.date = 1;
day1.mon++;
...
登录后发布评论
暂无评论,来抢沙发