博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
每日一九度之 题目1043:Day of Week
阅读量:5039 次
发布时间:2019-06-12

本文共 2128 字,大约阅读时间需要 7 分钟。

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:7336

解决:2563

题目描述:

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 200114 October 2001
样例输出:
TuesdaySunday
提示:

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

已知年月日,计算星期的公式有两个,一个是蔡勒公式,另一个就是基姆拉尔森计算公式。

具体的我也就不写了,大家可以百度。O(∩_∩)O哈哈~

我用的是基姆拉尔森计算公式。可以试着用蔡勒公式做下。但是那个比这个麻烦一点,因为还要计算出世纪c。

//Asimple#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x7fffffffusing namespace std;const int maxn = 115;typedef long long ll;int year, days;string moths[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};string str;string weeks[]={ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday"};int main(){ while( cin >> days >> str >> year ){ int m; for(int i=0; i<13; i++){ if( str == moths[i] ){ m = i + 1; break; } } if( m == 1 || m == 2 ){ m += 12; year --; } int a = (days + 2 * m + 3 * (m + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7; cout << weeks[a] << endl; } return 0;}

 

转载于:https://www.cnblogs.com/Asimple/p/5896342.html

你可能感兴趣的文章
使用ERStudio创建数据表与ER图
查看>>
ubuntu防火墙设置
查看>>
100步问题
查看>>
PLSQL Persistent State文摘
查看>>
对PostgreSQL中bufmgr.c的进一步学习
查看>>
PostgreSQL在何处处理 sql查询之四十四
查看>>
STL: reverse
查看>>
2017-10-15 NOIP模拟赛
查看>>
[学习笔记]设计模式之Proxy
查看>>
Asp.net MVC 中Ajax的使用 [分享]
查看>>
SQL SERVER 2008数据库的表中修改字段的数据类型后,不能保存
查看>>
java基础 (四)之集合
查看>>
单页网站不是梦,几款国外的单页网站创建工具
查看>>
分享30个高品质的抽象网页背景素材
查看>>
NavBarControl 左侧菜单
查看>>
转-设置/使用反向代理服务器
查看>>
转-editplus 配置
查看>>
[OI模拟赛]2017.8.24 Day5
查看>>
<Effective C++>读书摘要--Implementations<一>
查看>>
linux route命令学习
查看>>