简洁做法

/*
描述
We now use the Gregorian style of dating in Russia. The leap years are years with number divisible by 4 but not divisible by 100, or divisible by 400. For example, years 2004, 2180 and 2400 are leap. Years 2005, 2181 and 2300 are not leap. Your task is to write a program which will compute the day of week corresponding to a given date in the nearest past or in the future using today’s agreement about dating.
输入描述:
There is one single line contains the day number d, month name M and year number y(1000≤y≤3000). The month name is the corresponding English name starting from the capital letter.
输出描述:
Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case. Month and Week name in Input/Output: January, February, March, April, May, June, July, August, September, October, November, December Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
*/

#include<iostream>
#include<string>
#include<vector>

using namespace std;


int monthDays[2][12] = {
    {31,28,31,30,31,30,31,31,30,31,30,31},        // not leap year
    {31,29,31,30,31,30,31,31,30,31,30,31}        // leap year
};


bool isLeapYear(int year) {
    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        return true;
    return false;
}


int main() {
    int day=0,year=0,mon=0;
    int n = 0,week_day=0;
    string month;
    vector<string>M({ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" });
    vector<string> W({ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" });
    while (cin >> day >> month >> year)
    {
        for (int i = 0; i < M.size(); ++i)
            if (M[i] == month)
                mon = i;
        n = 0;
        for (int i = 0; i < year; ++i)
            n += isLeapYear(i) ? 366 : 365;
        for (int i = 0; i < mon; ++i)
            n += monthDays[isLeapYear(year)][i];
        n += day;
        n = n + 5;
        week_day = n % 7;
        cout << W[week_day] << endl;
    }
    return 0;
}