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;
}
随机推荐
- 【TCP/IP网络编程】:09套接字的多种可选项
本篇文章主要介绍了套接字的几个常用配置选项,包括SO_SNDBUF & SO_RCVBUF.SO_REUSEADDR及TCP_NODELAY等. 套接字可选项和I/O缓冲大小 前文关于套接字的 ...
- 一条SQL注入引出的惊天大案
前情回顾: WAF公司拦截到一个神秘的HTTP数据包,在这个包的表单字段中发现了SQL语句.目标指向80端口,而这正是nginx公司的地盘.详情参见:一个HTTP数据包的奇幻之旅 虚拟机的世界 一个安 ...
- Ant Design中getFieldDecorator方法的特殊用法(小bug)
记录Ant Design中getFieldDecorator方法的特殊的一个用法 了解Ant Design表单的小伙伴都知道,getFieldDecorator在大部分情况下是用来绑定一个控件的,即像 ...
- AcWing 206. 石头游戏 矩阵乘法|矩阵快速幂
AcWing 206. 石头游戏 石头游戏在一个 n 行 m 列 (1≤n,m≤8) 的网格上进行,每个格子对应一种操作序列,操作序列至多有10种,分别用0~9这10个数字指明. 操作序列是一个长度不 ...
- FJUT-1370 记录一次解题过程
题目在福工院的1370 首先看题目,好家伙,全英文 那么大致的题意就是.有几个城市同在一条线上(相当于在x轴上),max i是第i个城市到其他所有城市的距离中的最大值,min i也就是所有中最小的. ...
- DP-01背包 (题)
nyoj 325 http://acm.nyist.net/JudgeOnline/problem.php?pid=325 zb的生日 时间限制:3000 ms | 内存限制:65535 KB ...
- 【 Tomcat 】tomcat8.0 基本参数调优配置-----(2)
Tomcat 的缺省配置是不能稳定长期运行的,也就是不适合生产环境,它会死机,让你不断重新启动,甚至在午夜时分唤醒你.对于操作系统优化来说,是尽可能的增大可使用的内存容量.提高CPU 的频率,保证文件 ...
- Python自带HTTP文件传输服务
一行命令搭建一个基于python的http文件传输服务 由于今天朋友想要一个文件,而我恰好有,因为这个文件比较大,网速不是很给力,所以想到了python自己有这么一个功能,这样不仅不需要下载其他软件, ...
- 安装dbeaver,The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.
在连接mysql时,出现了以下错误: 解决方法是 在数据库链接指定useUnicode=true&useSSL=false&characterEncoding=utf8&ser ...
- 关于爬虫的日常复习(16)—— pyspider的初高级用法