2008上交:Day of Week
- 题目描述:
-
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的更多相关文章
- 在离线环境中发布.NET Core至Windows Server 2008
在离线环境中发布.NET Core至Windows Server 2008 0x00 写在开始 之前一篇博客中写了在离线环境中使用.NET Core,之后一边学习一边写了一些页面作为测试,现在打算发布 ...
- Windows Server 2008 R2常规安全设置及基本安全策略
这篇文章主要介绍了Windows Web Server 2008 R2服务器简单安全设置,需要的朋友可以参考下 用的腾讯云最早选购的时候悲催的只有Windows Server 2008 R2的系统,原 ...
- Windows Server 2008 小操作汇总
用惯了Windows2003,去配置2008的时候还真有点摸不着头脑.干脆把有用到的都列在这里,方便后续查找. 一.安装IIS.Telnet 点击:开始 -> 管理工具 -> 服 ...
- Windows 2008 R2 安装sp1时未知错误的解决办法
最近在为Windows Server 2008 R2 打sp1补丁时出现“发生未知错误”,详细信息错误:0x800f0818: google后找到解决问题步骤,参照:http://www.wikiho ...
- 如何在Windows Server 2008 R2没有磁盘清理工具的情况下使用系统提供的磁盘清理工具
今天,刚好碰到服务器C盘空间满的情况,首先处理了临时文件和有关的日志文件后空间还是不够用,我知道清理C盘的方法有很多,但今天只分享一下如何在Windows Server 2008 R2没有磁盘清理工具 ...
- [vs2008]Visual Studio 2008 SP1添加或删除功能提示查找SQLSysClrTypes.msi文件
前言 今天接到领导布置的一个任务,是之前同事负责的项目.离职了,现在客户有些地方需要修改,由于我之前参与过,就落在我的头上了. 然后我就把代码弄了过来,打开发现其中需要用到水晶报表.(我觉得不好用,不 ...
- 利用SQL Server 2008 R2创建自动备份计划
本文主要利用SQL Server 2008 R2自带的"维护计划"创建一个自动备份数据的任务. 首先,启动 Sql Management studio,确保"SQL Se ...
- SQL Server 2008 阻止保存要求重新创建表的更改问题的设置方法
不是很理解为什么在2008中会加入阻止保存要求重新创建表的更改这个选项.症状表现为修改表结构的时候会"阻止"你.而且我遇到的情况是居然有的时候阻止你,有的时候不阻止你,摸不到头脑. ...
- Microsoft SQL Server 2008 R2 安装卸载
问题 问题1 标题: Microsoft SQL Server 2008 R2 安装程序 ------------------------------ 出现以下错误: Could not open k ...
随机推荐
- iOS-事件传递和响应机制
转自:http://www.jianshu.com/p/2e074db792ba 前言: 按照时间顺序,事件的生命周期是这样的: 事件的产生和传递(事件如何从父控件传递到子控件并寻找到最合适的view ...
- mac 地址分配
https://regauth.standards.ieee.org/standards-ra-web/pub/view.html#registries 34:96:72:3c:5d:d6mac 地址 ...
- activiti--6-------------------------------------连线(一般数据库表的查询顺序)
一.流程图 二.这次把流程图和Java类放在一个包下 三.代码 package com.xingshang.f_sequenceFlow; import java.io.InputStream; im ...
- linux.1:创建分区和文件系统
概述 使用 fdisk.gdisk 和 parted 创建和修改 MBR 和 GPT 分区在本教程中,学习磁盘分区和 Linux 文件系统相关内容,包括学习如何: 使用 mkfs 命令设置 ext2. ...
- QT设置QToolBar带有图标和文字
ui->mainToolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
- Linux vim 中文显示乱码解决方法
因为在windows下默认是gb编码,而我的vim默认是utf-8(gedit默认也是utf-8),所以打开会成乱码.改动了一下配置文件,使vi支持gb编码就好了.$vi ~/.vimrclet &a ...
- UIImageView 获取图片的 宽 高
该文章纯属这两天开发的经验之谈 并且也是平常没注意 这回发现的一个小方法 并且很实用 在开发中 提高了很大的效率 更加符合高保真的要求 通常 美术 切的一些图片 需要 :1还原的 现在 我们一般支持i ...
- iOS tabbar 上面更换任意图
tabbar 对add 上面的图片 有一层默认虚化 对于这种系统高度继承后的 控件 处理办法就是自定义 解决方案 1.放在tabbar 上的图片 不能太小 不然裁剪后 会很模糊 2 .通过裁剪 压缩的 ...
- jQuery自定义美化下拉框
在线演示 本地下载
- 第一篇、javascript变量和循环
一.代码存放位置 理论上放在body和head中都可以,但是推荐放在body代码块底部,因为Html代码是从上到下执行,如果Head中的js代码耗时严重,就会导致用户长时间无法看到页面,如果放置在bo ...