题目描述:

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 思路:先2016年7月3日(正好为星期日)为基准。求两日期之间的差值时可分别求两年份与1000年1月1日之间的距离,再做差。
#include <iostream>
#include <string.h>
using namespace std;
char Month[][]={"Null","January","February","March","April","May","June","July","August","September","October","November","December"};
char Week[][]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int mds[]={,,,,,,,,,,,,};
int d,y,m;
char mon[];
int sMon(char s[])
{
for(int i=;i<=;i++)
{
if(strcmp(Month[i],s)==)
{
return i;
}
}
}
bool isLeap(int year)
{
if((year%==&&year%!=)||year%==)
{
return true;
}
return false;
}
int caldays(int year)
{
int sum=;
for(int i=;i<=year;i++)
{
if(isLeap(i))
{
sum+=;
}
else sum+=;
}
return sum;
}
int standard;
int main()
{
standard+=caldays();
for(int i=;i<=;i++)
{
standard+=mds[i];
}
if(isLeap()) standard+=;
standard+=;
while(cin>>d>>mon>>y)
{
m=sMon(mon);
int days=;
days+=caldays(y-);//本年不算
for(int i=;i<m;i++)//本月不算
{
days+=mds[i];
}
if(m>&&isLeap(y)) days+=;
days+=d;
int diff=days-standard;
if(diff>=)
{
diff%=;
cout<<Week[diff]<<endl;
}
else
{
diff=-diff;
diff%=;
if(diff!=) diff=-diff;
cout<<Week[diff]<<endl;
}
}
return ;
}

2008上交:Day of Week的更多相关文章

  1. 在离线环境中发布.NET Core至Windows Server 2008

    在离线环境中发布.NET Core至Windows Server 2008 0x00 写在开始 之前一篇博客中写了在离线环境中使用.NET Core,之后一边学习一边写了一些页面作为测试,现在打算发布 ...

  2. Windows Server 2008 R2常规安全设置及基本安全策略

    这篇文章主要介绍了Windows Web Server 2008 R2服务器简单安全设置,需要的朋友可以参考下 用的腾讯云最早选购的时候悲催的只有Windows Server 2008 R2的系统,原 ...

  3. Windows Server 2008 小操作汇总

    用惯了Windows2003,去配置2008的时候还真有点摸不着头脑.干脆把有用到的都列在这里,方便后续查找. 一.安装IIS.Telnet      点击:开始 -> 管理工具 -> 服 ...

  4. Windows 2008 R2 安装sp1时未知错误的解决办法

    最近在为Windows Server 2008 R2 打sp1补丁时出现“发生未知错误”,详细信息错误:0x800f0818: google后找到解决问题步骤,参照:http://www.wikiho ...

  5. 如何在Windows Server 2008 R2没有磁盘清理工具的情况下使用系统提供的磁盘清理工具

    今天,刚好碰到服务器C盘空间满的情况,首先处理了临时文件和有关的日志文件后空间还是不够用,我知道清理C盘的方法有很多,但今天只分享一下如何在Windows Server 2008 R2没有磁盘清理工具 ...

  6. [vs2008]Visual Studio 2008 SP1添加或删除功能提示查找SQLSysClrTypes.msi文件

    前言 今天接到领导布置的一个任务,是之前同事负责的项目.离职了,现在客户有些地方需要修改,由于我之前参与过,就落在我的头上了. 然后我就把代码弄了过来,打开发现其中需要用到水晶报表.(我觉得不好用,不 ...

  7. 利用SQL Server 2008 R2创建自动备份计划

    本文主要利用SQL Server 2008 R2自带的"维护计划"创建一个自动备份数据的任务. 首先,启动 Sql Management studio,确保"SQL Se ...

  8. SQL Server 2008 阻止保存要求重新创建表的更改问题的设置方法

    不是很理解为什么在2008中会加入阻止保存要求重新创建表的更改这个选项.症状表现为修改表结构的时候会"阻止"你.而且我遇到的情况是居然有的时候阻止你,有的时候不阻止你,摸不到头脑. ...

  9. Microsoft SQL Server 2008 R2 安装卸载

    问题 问题1 标题: Microsoft SQL Server 2008 R2 安装程序 ------------------------------ 出现以下错误: Could not open k ...

随机推荐

  1. 在普通网页中如何调用html5+的plus对象

    <script> //用法: HTML5+的plus对象,必须由click事件触发后,才能在普通网页中使用.所以在没有click的情况下,调用本文件可以解决问题! //在代码中使用: pl ...

  2. Java mail 发送邮件 主题(标题)乱码

    最近开发遇到Javamail  发送邮件标题乱码问题,腾讯.网易邮箱不会乱码,阿里邮箱  标题则会乱码.解决办法: String subject = MimeUtility.encodeWord(ma ...

  3. GPS模块坐标偏差很大?

    回答这个问题,首先要了解几个概念: 火星坐标系:天朝有关部门规定,为了保证国家安全,所有的地图公司提供的地图必须对实际的GPS坐标进行一定的偏移,偏移后的GPS坐标系俗称火星坐标系,而这个偏移是不固定 ...

  4. mysql 修改表名的方法:sql语句

    在使用mysql时,经常遇到表名不符合规范或标准,但是表里已经有大量的数据了,如何保留数据,只更改表名呢? 可以通过建一个相同的表结构的表,把原来的数据导入到新表中,但是这样视乎很麻烦. 能否简单使用 ...

  5. 第10条:尽量用enumerate取代range

    核心要点: (1)enumerate函数提供了一种精简的写法,可以在遍历迭代器时获知每个元素的索引. (2)尽量用enumerate来改写那种将range与下标访问相结合的序列遍历代码. (3)可以给 ...

  6. Chrome Extension 扩展程序 小白入门

    Chrome Extension 扩展程序 前请说明:本文适用于之前从来没有接触过chrome extension扩展程序的同学~ 编写demo 创建项目文件夹chrome_ext_demo,在项目根 ...

  7. crond

    Crond介绍 Crond是linux系统用来定期执行命令或程序的工具. 服务 /etc/init.d/crond 命令 crontab [root@rhel6 script]# crontab -h ...

  8. HDU 之 I Hate It

                                                                                    I Hate It Time Limit ...

  9. RabbitMQ之Exchange

    交换机的作用: 生产者发送消息不会向传统方式直接将消息投递到队列中,而是先将消息投递到交换机中,在由交换机转发到具体的队列,队列在将消息以推送或者拉取方式给消费者进行消费,这和我们之前学习Nginx有 ...

  10. win7 apache+openssl 安装

    win7 apache+openssl 安装 博客分类: win7 apache+openssl 安装 win7 apache+openssl 安装  注:附件提供包含apache和openssl的安 ...