#include #include #include #include class Date { public: Date(const Date& d) = default; explicit Date(int year, int month, int day) : y(year), m(month), d(day) { } bool IsLeap() const { if (this->y % 100 == 0) { return this->y % 400 == 0; } else { return this->y % 4 == 0; } } std::string ToString() const { return std::to_string(this->d + 100).erase(0, 1) + '.' + std::to_string(this->m + 100).erase(0, 1) + '.' + std::to_string(this->y + 10000).erase(0, 1); } Date DaysLater(int days) const { int new_d = this->d; int new_m = (this->m + 9) % 12; int new_y = this->y - new_m / 10;; int64_t days_count = 365 * new_y + new_y / 4 - new_y / 100 + new_y / 400 + (new_m * 306 + 5) / 10 + (new_d - 1); days_count += days; new_y = (10000 * days_count + 14780) / 3652425; int ddd = days_count - (365 * new_y + new_y / 4 - new_y / 100 + new_y / 400); if (ddd < 0) { new_y = new_y - 1; ddd = days_count - (365 * new_y + new_y / 4 - new_y / 100 + new_y / 400); } int mi = (100 * ddd + 52) / 3060; int mm = (mi + 2) % 12 + 1; new_y = new_y + (mi + 2) / 12; int dd = ddd - (mi * 306 + 5) / 10 + 1; Date new_date(new_y, mm, dd); return new_date; } int DaysLeft(const Date& date) const { int d1 = this->d; int m1 = (this->m + 9) % 12; int y1 = this->y - m1 / 10;; int64_t days_count1 = 365 * y1 + y1 / 4 - y1 / 100 + y1 / 400 + (m1 * 306 + 5) / 10 + (d1 - 1); int d2 = date.d; int m2 = (date.m + 9) % 12; int y2 = date.y - m2 / 10;; int64_t days_count2 = 365 * y2 + y2 / 4 - y2 / 100 + y2 / 400 + (m2 * 306 + 5) / 10 + (d2 - 1); return days_count2 - days_count1; } private: int y; int m; int d; };