题解 | #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;
    }
}
全部评论

相关推荐

09-29 17:44
已编辑
蔚来_测(准入职员工)
//鲨鱼辣椒:见不了了我实习了四个月上周再投筛选了一天就给我挂了
点赞 评论 收藏
分享
牛客771574427号:恭喜你,华杰
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务