/*Конструктор Date(int year, int month, int day)

Метод bool IsLeap() const, возвращающий true в случае, если год является високосным и false в противном случае.

Метод std::string ToString() const, возвращающий строковое представление даты в формате dd.mm.yyyy.

Метод Date DaysLater(int days) const, возвращающий дату, которая наступит спустя days дней от текущей.

Метод int DaysLeft(const Date& date) const, возвращающий разницу между указанной и текущей датой (в днях).*/
#include <iostream>
#include <string>
#include <ctime>
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 % 4 == 0) this->mouth_days[1]++;
  }
  bool IsLeap() const {
    return year % 4 == 0;
  }
  bool operator==(const Date &date) const {
    return this->day == date.day &&
        this->year == date.year &&
        this->mouth == date.mouth;
  }
  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) {
    Date New_date(this->year, this->mouth, this->day);
    if (CheckFreeDaysToMoth(days)) {
      New_date.day++;
      return New_date;
    } else {
      int delta_days = 0;
      while (days) {
        delta_days = New_date.mouth_days[mouth - 1] - New_date.day;
        if (delta_days >= 0) {
          days -= delta_days + 1;
          New_date.day = 1;
          New_date.mouth++;
        } else {
          days += delta_days;
          New_date.day = -delta_days;
          New_date.mouth++;
        }
        if (New_date.mouth > 12) {
          New_date.year++;
          New_date.mouth = 1;
          if (New_date.year % 4 == 0) New_date.mouth_days[1]++;
          else if (New_date.mouth_days[1] == 29) New_date.mouth_days[1]--;
        }
      }
      return New_date;
    }
  }
  int DaysLeft(const Date &date) {
    int k = 0;
    Date tmp_date(date.year, date.mouth, date.day);
    while (!(tmp_date == date)) {
      k++;
      tmp_date = tmp_date.DaysLater(k);
    }
    return k;
  }
};