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;
}
随机推荐
- CentOS7.2 部署Ceph分布式存储
1.1 环境准备 主机名 IP地址 ceph-admin 192.168.16.220 ceph-node1,ceph-mon 192.168.16.221 ceph-node2,ceph-mon 1 ...
- Class 'org.apache.tomcat.jdbc.pool.DataSource' not found
把项目移动到新的运行环境时,明明包都导入了,项目也放进tomcat里面了,但是还会找不到该类 解决方法:项目右键选择底下的Properties ->project facets ->jav ...
- 【转】Matlab多项式拟合
转:https://blog.csdn.net/hwecc/article/details/80308397 例: x = [0.33, 1.12, 1.41, 1.71, 2.19] y = [0. ...
- 基于Spring封装的Javamail实现邮件发送
1.依赖 <dependency> <groupId>org.springframework</groupId> <artifactId>spring- ...
- 【转】15个超炫的HTML5效果
英文原文:http://www.hongkiat.com/blog/15-html5-experiments/ 翻译:iteye 乔布斯没有给Flash任何机会,微软新推出的Windows 8 ...
- C#实现DataTable转.CSV文件
将DataTable转换成CSV文件是一种常见的转换形式,主要通过遍历Table的每行,再对每行遍历每列,实现对数据的读取,然后用分隔符分隔Table的每个栏位数据,把读取的字符写入到CSV文件中.这 ...
- 如何应用threejs实现立方体每个面用图片替换
var geometry = new THREE.BoxGeometry(200, 200, 200);var materialsbg = []; for (var i = 0; i < geo ...
- EFK教程(5) - ES集群开启用户认证
基于ES内置及自定义用户实现kibana和filebeat的认证 作者:"发颠的小狼",欢迎转载 目录 ▪ 用途 ▪ 关闭服务 ▪ elasticsearch-修改elastics ...
- 玩转Django2.0---Django笔记建站基础九(一)(Auth认证系统)
第九章 Auth认证系统 Django除了有强大的Admin管理系统之外,还提供了完善的用户管理系统.整个用户管理系统可分为三大部分:用户信息.用户权限和用户组,在数据库中分别对应数据表auth_us ...
- 指定表单使用的路由 Specifying the Route Used by a Form