You are viewing a single comment's thread. Return to all comments →
C++
bool is_julian(int year) { return (year % 4 == 0); } bool is_gregorian(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } string additional_zero(int n) { return (n < 10 ? "0" + to_string(n) : to_string(n)); } string dayOfProgrammer(int year) { vector<int> month_days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int month = 0; int year_day = 256; if (year == 1918) { year_day += 13; } else if (year >= 1919) { if (is_gregorian(year)) { month_days[1] = 29; } } else { if (is_julian(year)) { month_days[1] = 29; } } while (year_day > month_days[month]) { year_day -= month_days[month]; month++; } month += 1; return additional_zero(year_day) + "." + additional_zero(month) + "." + to_string(year); }
Seems like cookies are disabled on this browser, please enable them to open this website
Day of the Programmer
You are viewing a single comment's thread. Return to all comments →
C++