1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include <iostream> #include <vector> #include <string> using namespace std;
const vector<string> months{ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
const vector<string> weekdays{ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
int days_in_months[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
int get_month_from_str(const string src) { int i = 0; for (; i < months.size(); i++) { if (months[i] == src) return i + 1; } return -1; }
bool is_leap(int year) { return year % 400 == 0 || (year % 100 != 0 && year % 4 == 0); }
int main() { int day, year; string month_str; while (cin >> day >> month_str >> year) { int month = get_month_from_str(month_str); int delta_day = 0; for (int i = 1000; i < year; i++) { delta_day += is_leap(i) + 365; } days_in_months[2] = is_leap(year)? 29: 28; for (int start_month = 1, start_day = 1; ;) { if (start_month != month) { delta_day += days_in_months[start_month]; start_month++; } else { delta_day += day - 1; break; } } int res = (delta_day + 2) % 7; cout << weekdays[res] << endl; } return 0; }
|