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;
}
随机推荐
- GraphicsLab Project之Diffuse Irradiance Environment Map
作者:i_dovelemon 日期:2020-01-04 主题:Rendering Equation,Irradiance Environment Map,Spherical Harmonic 引言 ...
- Windows下使用 npm 命令安装 Appium(详)
本文主要讲述如何在 Windows 系统上通过 npm 命令行安装 appium Windows 桌面版请在官网选择对应版本下载安装. 官网链接 TestHome 百度网盘下载链接 Tips:Appi ...
- 人生苦短,我用Python(6)
1.分隔.合并字符串 分隔字符串是把字符串分隔为列表,而合并字符串是把列表合并为字符串,分割字符串和合并字符串可以看作是互逆操作. (1)分隔字符串 字符串对象得split()方法可以实现字符串分隔, ...
- django 数据库连接出现的问题
mysqlclient 1.3.3 or newer is required; you have 0.7.11: 解决方法: 将报错文件中的如下代码注释: if version < (1, 3, ...
- VS从标准输入读入文件
1.点击[生成],在对应目标平台[64 or 32]文件夹下的[release]或[debug]下找到可执行文件 2.读取销售记录文件 1)打开cmd,将销售记录文件和可执行文件放在同一文件夹下 2) ...
- Java虚拟机OOM问题和四大引用问题简述
一.请你谈谈实际的项目中在Java虚拟机会抛出哪些异常,每个异常都是怎么产生的? 1.java.lang.StackOverflowError 栈空间满了 public static void sta ...
- MAVEN配置及Spring Tool Suite的Maven配置
1.下载Maven http://maven.apache.org/download.cgi 如图点击下载即可 2.Maven配置 2.1配置本地仓库 创建目录maven-repository如图所示 ...
- 开启我的python之路,第一节,git版本管理工具
git版本管理工具 一.git功能与结构 1.Git是分布式管理系统,服务端和客户端都有版本控制功能,都能进行代码的提交,合并 2.git分为工作区,暂存区,本地仓库和远程仓库 二.git安装与查看 ...
- Spark集群-Standalone 模式
Spark 集群相关 table td{ width: 15% } 来源于官方, 可以理解为是官方译文, 外加一点自己的理解. 版本是2.4.4 本篇文章涉及到: 集群概述 master, worke ...
- 一个简易的 LED 数字时钟实现方法
这个应该是已经有很多人做过的东西,我应该只是算手痒,想写一下,所以,花了点时间折腾了这个,顺便把 Dark Mode 的处理也加上了. 首先可以很明确的一点,这个真没技术含量存在,只是需要点耐心. L ...