Bovine Birthday(思维题)
发布日期:2021-10-16 05:05:09
浏览次数:9
分类:技术文章
本文共 2098 字,大约阅读时间需要 6 分钟。
Bovine Birthday
Time Limit: 1000MS | Memory Limit: 65536K | |
Total 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:
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 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锻炼敲代码能力。#include #include 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< <
转载地址:https://blog.csdn.net/sinat_37668729/article/details/77070862 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年03月29日 06时29分30秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
设计模式之单例模式实践
2019-04-28
彻底理解正向代理和反向代理
2019-04-28
一次频繁Full GC的排查过程,根源居然是它...
2019-04-28
【爬虫】简单十行代码爬取B站的B站弹幕
2019-04-28
Servlet 体系结构
2019-04-28
Java笔记—语法
2019-04-28
Java笔记—数组
2019-04-28
Java笔记—继承
2019-04-28
MySQL的数据类型
2019-04-28
洛谷 P1886 滑动窗口 /【模板】单调队列
2019-04-28
洛谷 P3367 【模板】并查集
2019-04-28
【算法学习】高级数据结构2 种类并查集
2019-04-28
洛谷 P1525 关押罪犯【种类并查集】
2019-04-28
洛谷 P2024 [NOI2001]食物链【种类并查集】
2019-04-28
POJ 1703 Find them, Catch them【种类并查集】
2019-04-28
POJ 2492 A Bug‘s Life【种类并查集】
2019-04-28
POJ 2236 Wireless Network【并查集】
2019-04-28
LeetCode C++ 214. Shortest Palindrome【字符串】困难
2019-04-28
洛谷 P2580 于是他错误的点名开始了【字典树/Map】
2019-04-28