文章
4
粉丝
422
获赞
14
访问
45.7k
#include <bits/stdc++.h>
using namespace std;
typedef struct date {
int year;
int month;
int day;
}date;
//闰年判断
bool is366 (int year) {
if (year % 4 == 0 && year % 100 != 0)
return true;
if (year % 400 == 0)
return true;
return false;
}
int main () {
date begin, end;
int mon[13] = {0, 31, 28, 31, 30, 31, 30 , 31, 31, 30, 31, 30, 31};
scanf("%4d%2d%2d", &begin.year, &begin.month, &begin.day);
scanf("%4d%2d%2d", &end.year, &end.month, &end.day);
int a = 0;
//按相差年份计算天数
a += (end.year - begin.year) * 365;
//同步年,按相差月数计算天数
for(int i = begin.month; i < end.month; ++i)
a += mon[i];
//同步年月,计算相差天数
a += end.day - begin.day;
// cout << "over:" << a << endl;
//检查开始年是否少加一天
if (begin.month <= 2 && begin.year != end.year) a += 1;
if (begin.month <= 2 && end.month > 2) a += 1;
// cout << "begin:" << a << endl;
//判断中间年是否是闰年
for(i...
登录后发布评论
暂无评论,来抢沙发