原题链接:https://leetcode-cn.com/problems/day-of-the-week/
class Solution {
public:
bool isLeapYear(int year) {
return year%400 == 0 || year%4 == 0 && year%100 != 0;
}
string dayOfTheWeek(int day, int month, int year) {
vector<string> week = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
vector<int> mon = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
// 1970.12.31 Thursday
int count = 365 * (year - 1971) + (year-1969)/4;
for (int i = 1; i < month; i ++ ) {
count += mon[i-1];
if (i == 2 && isLeapYear(year)) count += 1;
}
count += day;
return week[(3 + count) % 7];
}
};