HDU2133 What day is it【水题】
来源:互联网 发布:超人计划软件 编辑:程序博客网 时间:2024/05/22 13:00
What day is it
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3976 Accepted Submission(s): 1164
Problem Description
Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me what day it is ?
Input
There are multiply cases.
One line is one case.
There are three integers, year(0<year<10000), month(0<=month<13), day(0<=day<32).
Output
Output one line.
if the date is illegal, you should output "illegal". Or, you should output what day it is.
Sample Input
2007 11 17
Sample Output
Saturday
Author
LGX
Source
HDU 2007-11 Programming Contest_WarmUp
题目大意:给你一个日期,先判断日期是否合法,不合法输出"illegal",继续下组数据输入。合
法的话,计算出该日期是周几,然后输出相应星期的英文单词。参考日期是2007年11月17日是
星期六。
思路:按2007年11月17日来算太过繁琐,因为公元0001年1月1日是星期一,这样递推算到要计
算的日期就变简单了不少。统计从1年1月1日到给出日期的总天数是多少,因为只需要计算星期,
所以只要对7取余的值即可。用了数组来保存每月天数和星期的单词,简洁了不少。
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;int a[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};int b[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};char s[8][10] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};bool IsRunNian(int year){ if((year%4==0 && year%100!=0) || year%400==0) return true; return false;}int main(){ int year,month,day; while(cin >> year >> month >> day) { if(IsRunNian(year)) { if(day > a[month] || month == 0 || day == 0) { cout << "illegal" << endl; continue; } } else { if(day > b[month] || month == 0 || day == 0) { cout << "illegal" << endl; continue; } } int sum = 0; for(int i = 1; i < year; ++i) { if(IsRunNian(i)) sum += 366; else sum += 365; sum %= 7; } for(int i = 0; i < month; ++i) { if(IsRunNian(year)) sum += a[i]; else sum += b[i]; sum %= 7; } sum += day; sum %= 7; cout << s[sum] << endl; } return 0;}
0 0
- HDU2133 What day is it【水题】
- HDU2133:What day is it
- HDU2133 What day is it
- 【hdu2133】What day is it
- What day is it hdu2133(终于AC)
- HDU2133 What day is it 模拟题
- What day is it 2133
- hdu1308 What Day Is It
- HDU 2133 - What day is it
- HDU 2133 What day is it
- HDU 2133 What day is it
- hdu 2133 What day is it
- HDU:2133 What day is it
- hdu 2133 what day it is?
- 杭电 1308 What Day Is It?
- zoj 1256 What Day Is It?
- hdu 2133 What day is it
- hdu 2133 What day is it
- poj 1276 Cash Machine 多重背包
- POJ 1159-Palindrome(dp_回文串+滚动数组)
- Lucene-搜索索引
- To April
- c++11 条款20:使用std::weak_ptr作为一个类似std::share_ptr但却能悬浮的指针
- HDU2133 What day is it【水题】
- 运用 Ntop 监控网络流量
- 并发、多线程下Lucene需要注意的地方
- UItextView和UItextfiled 使用
- SQL语句快速查询存在某个值的所有存储过程
- 如何理解Lucene的Index(索引)文档模型
- 串口通信--VHDL
- Android开发:一句代码搞定eclipse查看v4源码
- 推荐两个小工具MediaInfo 和 netpersec