#include <cmath>
#include <string>
using std::string;
class Date {
public:
int year;
int month;
int day;
Date(int year, int month, int day) {
this->year = year;
this->month = month;
this->day = day;
}
bool IsLeap() const {
return this->LeapYear(this->year);
}
std::string ToString() const {
char ch[12] = { '\0' };
snprintf(ch, sizeof(ch), "%02d.%02d.%04d", day, month, year);
string str(ch);
return str;
}
Date DaysLater(int days) {
int year = this->year,
month = this->month,
day = this->day + days;
int amount = this->DaysInYear(month, year);
while (day > amount) {
day -= amount;
if (++month > 12) {
month = 1;
year += 1;
}
amount = this->DaysInYear(month, year);
}
return Date(year, month, day);
}
int DaysLeft(const Date& date) {
int a = (14 - month) / 12;
int y = year + 4800 - a;
int m = (153 * (month + 12 * a - 3) + 2) / 5;
int num1 = day + m + 365*y + y/4 - y/100 + y/400 - 32045;
a = (14 - date.month) / 12;
y = date.year + 4800 - a;
m = (153 * (date.month + 12 * a - 3) + 2) / 5;
int num2 = date.day + m + 365*y + y/4 - y/100 + y/400 - 32045;
return abs(num1 - num2);
}
private:
bool LeapYear(int year) const {
if (year % 4 != 0)
return false;
else if (year >= 100 && year % 100 == 0 && year % 400 != 0)
return false;
return true;
}
int DaysInYear(int month, int year) {
if (month < 8) {
if (month == 2) {
int res = 28;
if (LeapYear(year)) res++;
return res;
}
return 30 + (month % 2);
}
return 31 - (month % 2);
}
};