#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
struct Date{
int year;
int month;
int day;
Date(int y = 0, int m = 0, int d = 0):
year(y), month(m), day(d) {}
Date & readIn() {
cin >> year >> month >> day;
return *this;
}
void swap(Date & rhs) {
Date t(*this);
*this = rhs;
rhs = t;
}
};
bool is_leap(int year) {
return (year % 400)|| (year % 4 && year % 100);
}
bool operator < (const Date & lhs, const Date & rhs) {
return (lhs.year < rhs.year) ||
(lhs.year == rhs.year) && (lhs.month < rhs.month) ||
(lhs.year == rhs.year) && (lhs.month == rhs.month && lhs.day < rhs.day);
}
int days_of_month(int year,int month) {
switch(month) {
case 1: case 3: case 5:case 7:
C++ 求两日期间相隔天数
最新推荐文章于 2024-05-07 16:18:03 发布
这篇博客介绍了一个C++程序,用于计算两个日期之间的天数差异。程序定义了一个Date结构体,包含了年、月、日,并实现了日期的比较、读取以及闰年的判断。通过不断调整日期使其相邻,然后累加每个月的天数,最终计算出两个日期之间的总天数差。
摘要由CSDN通过智能技术生成