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;
}
随机推荐
- ES6异步操作之Promise
一直以来觉得异步操作在我心头像一团迷雾,可是它重要到我们非学不可,那就把它的面纱解开吧. ES6 诞生以前,异步编程的方法,大概有下面四种. 回调函数 事件监听 发布/订阅 Promise 对象 异步 ...
- ReentrantLock 源码分析从入门到入土
回答一个问题 在开始本篇文章的内容讲述前,先来回答我一个问题,为什么 JDK 提供一个 synchronized 关键字之后还要提供一个 Lock 锁,这不是多此一举吗?难道 JDK 设计人员都是沙雕 ...
- Eclipse配置运行内存
对于一些大的项目,运行时等待过长可能出现内存溢出现象,需要重新配置IDE运行内存大小,如下: 1.配置Eclipse.ini 如图再改大点: -Xms512m-Xmx512m 2.JDK内存扩大 Wc ...
- 如何在oracle中缩小临时表空间?ORA-01652无法在表空间中扩展temp
查询临时表空间有多大: SQL> SELECT tablespace_name, file_name, bytes FROM dba_temp_files WHERE tablespace_na ...
- 【转】SQL语句面试题
1.一道SQL语句面试题,关于group by表内容:2005-05-09 胜2005-05-09 胜2005-05-09 负2005-05-09 负2005-05-10 胜2005-05-10 负2 ...
- Prometheus+Alertmanager+Grafana监控组件容器部署
直接上部署配置文件 docker-compose.yml version: '3' networks: monitor: driver: bridge services: prometheus: im ...
- cogs 615. 韩国明星 STL map
615. 韩国明星 ★★ 输入文件:star.in 输出文件:star.out 简单对比时间限制:2 s 内存限制:128 MB [问题描述] 在LazyCat同学的影响下,Roby同 ...
- 用K-Means聚类分析做客户分群
聚类指的是把集合,分组成多个类,每个类中的对象都是彼此相似的.K-means是聚类中最常用的方法之一,它是基于点与点距离的相似度来计算最佳类别归属. 在使用该方法前,要注意(1)对数据异常值的处理:( ...
- 头条一面竟然问我Maven?
maven package和maven install 有什么区别? 你常用的maven命令有哪些? <dependencyManagement> 是干什么的? 还有用过其它构建工具吗? ...
- http请求头中的content-type属性
在HTTP请求中,我们每天都在使用Content-Type来指定不同格式的请求信息,但是却很少有人去全面了解Content-Type中允许的值有多少,因此这里来了解一下Content-Type的可用值 ...