题目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. 「CodeForces 476A」Dreamoon and Stairs

    Dreamoon and Stairs 题意翻译 题面 DM小朋友想要上一个有 \(n\) 级台阶的楼梯.他每一步可以上 \(1\) 或 \(2\) 级台阶.假设他走上这个台阶一共用了 \(x\) 步 ...

  2. 你确定你了解什么是linux系统?

    1.什么是linux发行版 就Linux的本质来说,它只是操作系统的核心,负责控制硬件.管理文件系统.程序进程等,并不给用户提供各种工具和应用软件.所谓工欲善其事,被必先利其器,一套在优秀的操作系统核 ...

  3. html 拨打电话

    其实就一行 你们别想太复杂 直接在手机中访问 点击a标签(如果你在pc端我就没话说了) <a href="tel:13999999999"></a>

  4. c语言一道题

    C语言中,a=b=c,a=b==c,a==(b=c),a==(b==c)有什么区别 main(){inta=1,b=2,c=3;printf("%d,%d,%d,%d\n",a=b ...

  5. FTP服务器虚拟用户配置

    FTP服务配置问题及解决方案 使用被动模式,设置云主机IP为被动模式数据传输地址:在配置文件内添加 pasv_enable=YES pasv_promiscuous=YES pasv_address= ...

  6. Qt5学习(2)

    1.学习了qt quick application 这是一种跟application不同的设计方式.主要就是靠“拖拖拽拽”,然后设置属性(颜色,大小),布局(margins等),然后要注意控件的从属关 ...

  7. Keystone V3 API Examples

    There are few things more useful than a set of examples when starting to work with a new API. Here a ...

  8. C#调用Fortran生成的DLL的方法报内存不足

    最近在研究一个程序,公司给的,程序是VB写的,程序里面还有一个计算的模型,用Fortran语言写的. 在调试到这个模型里面的方法时报错,说是内存不足,于是就在网上查找方法,看了两篇博客之后问题解决了. ...

  9. 记一次docker镜像导出导入流程

    目标:导出测试环境的镜像到本地机器 过程: 测试机: docker save -o /Dockerfile/crontabService/php72.tar lnmp72:v1.4 压缩,要不文件太大 ...

  10. 替代not in 和 in 的办法

    在程序中,我们经常会习惯性的使用in和not in,在访问量比较小的时候是可以的,但是一旦数据量大了,我们就推荐使用not exists或者外连接来代替了.如果要实现一张表有而另外一张表没有的数据时, ...