Bovine Birthday(思维题)
来源:互联网 发布:tplink路由器访客网络 编辑:程序博客网 时间:2024/06/05 21:09
Bovine Birthday
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2211 Accepted: 1020
Description
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:
* 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.
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.
Input
* Line 1: Three space-separated integers that represent respectively the year, month (range 1..12), and day of a date.
Output
* 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).
Sample Input
2003 5 25
Sample Output
sunday
Hint
INPUT DETAILS:
May 25, 2003
OUTPUT DETAILS:
May 25, 2003
OUTPUT DETAILS:
May 2003Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 1718 19 20 21 22 23 2425 26 27 28 29 30 31
题意:
给你某一年1月1日是周一,然后让你随便输入一个日期,判断是周几。
思路:
for循环,对每年每月情况判断。
代码:
#include <iostream>#include <cstring>#include <string>using namespace std;string week[7]={"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"};bool IsLeapYear(int y) //判断是否是闰年{ return (y%100!=0&&y%4==0)||(y%400 == 0);}int main(){ int year,month,day; int i,j,k; cin>>year>>month>>day; int w=1; for(i=1800;i<=2100;i++) { for(j=1;j<=12;j++) { if(j==4||j==6||j==9||j==11) { for(k=1;k<=30;k++) { w=(w+1)%7; if(year==i&&j==month&&k==day)cout<<week[w]<<endl; } } else if(j==2) { if(IsLeapYear(i)) for(k=1;k<=29;k++){w=(w+1)%7;if(year==i&&j==month&&k==day)cout<<week[w]<<endl;} else for(k=1;k<=28;k++){w=(w+1)%7;if(year==i&&j==month&&k==day)cout<<week[w]<<endl;} } else { for(k=1;k<=31;k++) { w=(w+1)%7; if(year==i&&j==month&&k==day)cout<<week[w]<<endl; } } } } return 0;}
锻炼敲代码能力。
阅读全文
0 0
- Bovine Birthday(思维题)
- poj 3407 Bovine Birthday
- poj 3047 Bovine Birthday
- POJ 3047 Bovine Birthday 笔记
- POJ 3047 Bovine Birthday 再想想
- lightoj-1104-Birthday Paradox【概率】(思维)
- 1648 Bovine Birthday【解题报告-蔡勒公式】
- LightOJ 1104 Birthday Paradox(生日悖论,思维)
- Light OJ:1104 Birthday Paradox(数学概率+思维)
- POJ 3047 Bovine Birthday 给出年月日求星期 蔡勒公式
- 【思维】LightOj Fibsieve`s Fantabulous Birthday 1008
- POJ 3175 Finding Bovine Roots (枚举)
- POJ 3175 Finding Bovine Roots(思路)
- Birthday (背包dp)
- birthday
- birthday
- birthday
- hdu 3866 Moonfang's Birthday 排序?贪心?二分?思维?
- Mongo索引
- mysql里面时间处理函数cast
- 互联网-高可用系列(一)-概念
- 使用Python3批量保存贴吧图片-附爬虫程序
- ida调试win64选择windbg
- Bovine Birthday(思维题)
- 队列的顺序存储和链式存储
- 用Jsoup写一个简单的爬虫,并把从网页上面爬下的数据保存到数据库中
- tensorflow读取数据
- GreenDao3.0的使用
- (吴恩达笔记 1-1)附——为什么用最小平方和做目标函数
- windows下通过cmd切换python2和python3版本
- CSS-overflow:auto溢出加滚动条
- 设计模式:接口隔离原则