问题描述:
有两个日期,求两个日期之间的天数,如果两个日期是连续的,
我们规定他们之间的天数为两天。
输入形式为YYYYMMDD,例如:
20110412
20110422
输出为:
11
#include<stdio.h>
#define ISYEAP(x) x%100!=0&&x%4==0||x%400==0?1:0
//定义宏判断是否是闰年,方便计算每月天数
int dayOfMonth[13][2] = {
0,0,
31,31,
28,29,
31,31,
30,30,
31,31,
30,30,
31,31,
31,31,
30,30,
31,31,
30,30,
31,31
}; //存放每月的天数
struct Date {
int Day;
int Month;
int Year;
void nextDay() {
Day++;
if (Day > dayOfMonth[Month][ISYEAP(Year)]) {
Day = 1;
Month++;
if (Month > 12) {
Month = 1;
Year++;
}
}
}
};
int buf[