题目1043:Day of Week

时间限制:1 秒

内存限制:32 兆

特殊判题:否

提交:1544

解决:609

题目描述:

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 2004, 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.

样例输入:
9 October 2001
14 October 2001
样例输出:
Tuesday
Sunday
提示:

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 <map>
#include <string>
using namespace std; int main(void)
{
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,30, 31};
map<string, int>Month;
int day, year, month, sumDay;
string strMonth;
Month.insert(make_pair("January", 1));
Month.insert(make_pair("February", 2));
Month.insert(make_pair("March", 3));
Month.insert(make_pair("April", 4));
Month.insert(make_pair("May", 5));
Month.insert(make_pair("June", 6));
Month.insert(make_pair("July", 7));
Month.insert(make_pair("August", 8));
Month.insert(make_pair("September", 9));
Month.insert(make_pair("October", 10));
Month.insert(make_pair("November", 11));
Month.insert(make_pair("December", 12)); while (cin >> day >> strMonth >> year)
{
sumDay = 0;
month = Month[strMonth];
for (int i = 1; i <= year - 1; i++)
{
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
{
sumDay += 366;
}
else
{
sumDay += 365;
}
}
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
days[2] = 29;
}
else
{
days[2] = 28;
}
for (int i = 1; i <= month - 1; i++)
{
sumDay += days[i];
}
sumDay += day; sumDay = sumDay % 7;
switch (sumDay)
{
case 1:
cout << "Monday" << endl;
break;
case 2:
cout << "Tuesday" << endl;
break;
case 3:
cout << "Wednesday" << endl;
break;
case 4:
cout << "Thursday" << endl;
break;
case 5:
cout << "Friday" << endl;
break;
case 6:
cout << "Saturday" << endl;
break;
case 0:
cout << "Sunday" << endl;
break;
default:
break;
}
}
return 0;
}

随机推荐

  1. verilog HDL 进击之路

    Verilog 进击之路 - 夯实基础第一节之结构化设计 随着数字电路设计的复杂化和专业化,传统的电路设计逐渐没落,Verilog HDL逐渐走入历史舞台.好多人并不是不会Verilog,而是缺乏细致 ...

  2. Spring应用事件(Application Event)

    Spring的事件为Bean与Bean的消息通信提供的支持.当一个Bean处理完了一个任务以后,希望另一个Bean知道并能做出相应的处理,这是我们就需要让另一个Bean监听当前Bean所发送的事件. ...

  3. awsl

    from enum import Enum, uniquefrom math import sqrtfrom random import randint import pygame @uniquecl ...

  4. sql计算上一周(解决了跨年会出错的问题)

    1.问题描述: 使用YEARWEEK('时间字段')=YEARWEEK(NOW())-1来筛选上一周数据时,当遇到跨年的时候会出现计算错误的问题. eg: 如上图,当前日期为2020年1月6日.上图标 ...

  5. zabbix 4.04 安装文档 - 基于CentOS 7.6

    1    安装前准备: 1.1   安装JDK 卸载openjdk # rpm -qa | grep java # yum remove java-1.8.0-openjdk # yum remove ...

  6. git版本管理工具(二)

    1.查看历史版本 ·git log ·git reflog 2.版本回退 ·git reset --hard HEAD^(HEAD代表当前版本) ·HEAD^代表回退到上一个版本 以此类推 ·HEAD ...

  7. Java 中级 学习笔记 2 JVM GC 垃圾回收与算法

    前言 在上一节的学习中,已经了解到了关于JVM 内存相关的内容,比如JVM 内存的划分,以及JDK8当中对于元空间的定义,最后就是字符串常量池等基本概念以及容易混淆的内容,我们都已经做过一次总结了.不 ...

  8. java 魔术

    每4个字节都有对应的含义

  9. python专题文件操作

    一 前言 本篇文章主要对文件操作进行说明,知识追寻者创作必属精品,读完本篇你将获得基础的文件操作能力,深入理解文件操作API,基础真的很重要,不管学什么知识,故看知识追寻者的专题系列真的很不错. 二 ...

  10. 分布式唯一ID自增(雪花算法)

    public class IdWorker { // ==============================Fields===================================== ...