#include #include #include class Date { private: int year; int mouth; int day; int mouth_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool CheckFreeDaysToMoth(int days) { return this->mouth_days[this->mouth] >= this->day + days; } public: Date(int year, int mouth, int day) { this->day = day; this->mouth = mouth; this->year = year; if (this->year % 400 == 0 || (this->year % 100 != 0 && this->year % 4 == 0)) this->mouth_days[1]++; } bool IsLeap() const { if (this->year % 400 == 0) return true; else if (this->year % 100 == 0) return false; return year % 4 == 0; } bool operator==(const Date &date) const { return this->day == date.day && this->year == date.year && this->mouth == date.mouth; } bool operator>(const Date &date) const { if (this->year > date.year) { return true; } else if (this->year < date.year) { return false; } else { if (this->mouth > date.mouth) { return true; } else if (this->mouth < date.mouth) { return false; } else { if (this->day > date.day) { return true; } else if (this->day < date.day) { return false; } else { return false; } } } } std::string ToString() { std::string t; if (this->day < 10) { t = "0" + std::to_string(this->day) + "."; } else { t = std::to_string(this->day) + "."; } if (this->mouth < 10) { t += "0" + std::to_string(this->mouth) + "."; } else { t += std::to_string(this->mouth) + "."; } if (this->year < 10) { t += "000" + std::to_string(this->year); } else if (this->year < 100) { t += "00" + std::to_string(this->year); } else if (this->year < 1000) { t += "0" + std::to_string(this->year); } else { t += std::to_string(this->year); } return t; } Date DaysLater(int days) const { int new_day = this->day; int new_mouth = (this->mouth + 9) % 12; int new_year = this->year - new_mouth / 10;; int64_t days_count = 365 * new_year + new_year / 4 - new_year / 100 + new_year / 400 + (new_mouth * 306 + 5) / 10 + (new_day - 1); days_count += days; new_year = (10000 * days_count + 14780) / 3652425; int tmp_day = days_count - (365 * new_year + new_year / 4 - new_year / 100 + new_year / 400); if (tmp_day < 0) { new_year = new_year - 1; tmp_day = days_count - (365 * new_year + new_year / 4 - new_year / 100 + new_year / 400); } int tmp_mouth = (100 * tmp_day + 52) / 3060; int tmp_new_mouth = (tmp_mouth + 2) % 12 + 1; new_year = new_year + (tmp_mouth + 2) / 12; int tmp_new_day = tmp_day - (tmp_mouth * 306 + 5) / 10 + 1; return Date(new_year, tmp_new_mouth, tmp_new_day); } int DaysLeft(const Date &date) { int k = 0; Date tmp_date_new(date.year, date.mouth, date.day); Date tmp_date_old(this->year, this->mouth, this->day); while (!(tmp_date_new == tmp_date_old)) { k++; if (tmp_date_new > tmp_date_old) tmp_date_old = tmp_date_old.DaysLater(1); else tmp_date_new = tmp_date_new.DaysLater(1); } return k; } };