求星期几的问题
来源:互联网 发布:网络用语dw什么意思 编辑:程序博客网 时间:2024/06/06 02:36
Bessie asked her friend what day of the week she was born on. She knew that she was born on 2003 May 25, but didn't know what day it was. Write a program to help. Note that no cow was born earlier than the year 1800.
Facts to know:
* January 1, 1900 was on a Monday.
* Lengths of months:
Jan 31 May 31 Sep 30 Feb 28 or 29 Jun 30 Oct 31 Mar 31 Jul 31 Nov 30 Apr 30 Aug 31 Dec 31
* Every year evenly divisible by 4 is a leap year (1992 = 4*498 so 1992 will be a leap year, but the year 1990 is not a leap year).
* The rule above does not hold for century years. Century years divisible by 400 are leap years, all other are not. Thus, the century years 1700, 1800, 1900 and 2100 are not leap years, but 2000 is a leap year.
* Line 1: Three space-separated integers that represent respectively the year, month (range 1..12), and day of a date.
* Line 1: A single word that is the day of the week of the specified date (from the lower-case list: monday, tuesday, wednesday, thursday, friday, saturday, sunday).
2003 5 25
sunday
很简单的一个题,把已知的星期几日期,到 要求的日期的天数,之间的天数加起来。然后%7就可以。 很快求写出来了,一直WA,最后才发现范围不是从1900年开始,而是从1800年开始的,浪费的时间很伤心。
#if 0#include<iostream>using namespace std;int sumd;int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};bool ok(int x){if((x%4==0&&x%100!=0)||(x%400==0))return 1;elsereturn 0;}int main(){int y,m,d;while(cin>>y>>m>>d && y+m+d){sumd=0;for(int i=1800; i<y; i++){if(ok(i)) {sumd+=366;}else{sumd+=365;}if(sumd>=7){sumd%=7;}}for(int i=1; i<m; i++) {if(i==2) {if(ok(y)) {sumd+=29; }else {sumd+=28; }}else{sumd+=a[i]; }if(sumd>=7){sumd%=7;}}sumd+=d;if(sumd>=7){sumd%=7;}if(sumd==6) {cout<<"monday"<<endl;}else if(sumd==0) {cout<<"tuesday"<<endl; }elseif(sumd==1){cout<<"wednesday"<<endl;}elseif(sumd==2){cout<<"thursday"<<endl;}elseif(sumd==3){cout<<"friday"<<endl;}elseif(sumd==4){cout<<"saturday"<<endl;}elseif(sumd==5) {cout<<"sunday"<<endl; }}}#endif
阅读全文
0 0
- 求星期几的问题
- java问题求星期几
- 关于利用基姆拉尔森计算公式与C++求星期几的问题
- 求算法:一段时间段内的星期几到星期几的集合
- 华为机试:星期几的问题
- 华为机试:星期几的问题
- 求哪一天是星期几
- 根据日期求星期几?
- 根据日期求星期几?
- 根据日期求星期几?
- 给出时间求星期几
- 日期类-求星期几
- 知道年月日求星期几
- 星期几问题
- 求给定日期为星期几的例子
- 求某年某月某日是星期几的公式
- 已知某天是星期几,求任意一天是星期几
- 星期几的算法
- IntelliJ Idea 常用快捷键列表
- EJB开发第一期---EJB开发配置
- Python基础总结(3)
- 建立LDA模型
- python继承关系之super函数
- 求星期几的问题
- java 三种outofmemory异常
- qt开发环境
- IntelliJ IDEA导航特性Top20
- poj3268Silver Cow Party之dijkstra解法
- JAVA编程题(初级):输入10个整数,排序后输出。
- 文章标题
- JZOJ1228. Matrix(2017.8B组)
- 洛谷P1607 [USACO09FEB]庙会班车Fair Shuttle