题解 | #Day of Week#
Day of Week
https://www.nowcoder.com/practice/a3417270d1c0421587a60b93cdacbca0
#include <iostream> #include <map> using namespace std; bool is_run(int y) { if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) return true; return false; } int main() { int d, y; string month; map<string, int> m; m["January"] = 1, m["February"] = 2, m["March"] = 3, m["April"] = 4, m["May"] = 5, m["June"] = 6, m["July"] = 7, m["August"] = 8, m["September"] = 9, m["October"] = 10, m["November"] = 11, m["December"] = 12; int month_day[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; string res[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; while (cin >> d >> month >> y) { int end_day = 0; for (int i = 1; i < y; i++) { if (is_run(i)) end_day += 366; else end_day += 365; } for (int i = 1; i < m[month]; i++) { if (i == 2) { if (is_run(y)) end_day += 29; else end_day += 28; } else { end_day += month_day[i]; } } end_day += d; end_day -= 1; int k = end_day % 7; cout << res[k] << endl; } return 0; }