题解 | #Day of Week#
Day of Week
http://www.nowcoder.com/practice/a3417270d1c0421587a60b93cdacbca0
#include<iostream>
#include<map>
using namespace std;
int main()
{
map<string,int> mp;
map<int,string> Mp;
mp["January"] = 1;
mp["February"] = 2;
mp["March"] = 3;
mp["April"] = 4;
mp["May"] = 5;
mp["June"] = 6;
mp["July"] = 7;
mp["August"] = 8;
mp["September"] = 9;
mp["October"] = 10;
mp["November"] = 11;
mp["December"] = 12;
Mp[0]="Sunday";Mp[1]="Monday";
Mp[2]="Tuesday";Mp[3]="Wednesday";
Mp[4]="Thursday";Mp[5]="Friday";
Mp[6]="Saturday";
int day,year;
string month;
while(cin >> day >> month >> year){
int m = mp[month];
if(m == 1 || m == 2){
m +=12;
year--;
}
int iWeek = ( day + 1 + 2 * m + 3 * ( m + 1 ) / 5 + year + year / 4 - year / 100 + year / 400 ) % 7;
cout << Mp[iWeek] << endl;
}
}