#include class Date { public: Date(int year, int month, int day): year_(year), month_(month), day_(day) {} bool IsLeap() const { return ((this->year_ % 4) == 0 && (this->year_ % 100 != 0)) || (this->year_ % 1000 == 0) || (this->year_ % 400 == 0); } std::string ToString() const { std::string d = std::to_string(this->day_); d = d.length() == 1 ? "0" + d : d; std::string m = std::to_string(this->month_); m = m.length() == 1 ? "0" + m : m; std::string y = std::to_string(this->year_); for (int i = y.length(); i < 4; ++i) { y = "0" + y; } return d + "." + m + "." + y; } Date DaysLater(int days) const { Date result(this->year_, this->month_, this->day_ + days); while (true) { int i_days = this->GetMonthDays(result); if (result.day_ <= i_days) { break; } result.day_ -= i_days; ++result.month_; if (result.month_ > 12) { result.month_ = 1; ++result.year_; } } return result; } int DaysLeft(const Date& date) const { return JDN(date.year_, date.month_, date.day_) - JDN(this->year_, this->month_, this->day_); } private: int JDN(const int& year, const int& month, const int& day) const { int a = (14 - month) / 12; int y = year + 4800 - a; int m = month + 12 * a - 3; return day + ((153 * m + 2) / 5) + (365 * y) + (y / 4) - (y / 100) + (y / 400) - 32045; } int GetMonthDays(const Date& date) const { static const int days_in_month[12] = {31, 28 , 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (date.month_ == 2 && date.IsLeap()) { return 29; } return days_in_month[date.month_ - 1]; } int year_, month_, day_; };