HDU 2133 What day is it
来源:互联网 发布:好听的歌曲推荐 知乎 编辑:程序博客网 时间:2024/05/16 08:40
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2133
What day is it
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3755 Accepted Submission(s): 1096
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).
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.
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
以1年1月1日是星期一为标准,算出1年1月1日到今天的天数,最后让天数对7取模即可。
#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<iostream>#include<algorithm>#include<sstream>#include<vector>#include<map>#include<stack>#include<list>#include<set>#include<queue>#define LL long long#define lson l,m,rt<<1#define rson m+1,r,rt<<1 | 1using namespace std;const int maxn=1005,maxe=100005,inf=1<<29;int n,m;int v[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};char ans[7][10] = {"Monday","Tuesday", "Wednesday","Thursday", "Friday","Saturday", "Sunday"} ;int judge(int n){ if(n%400==0||(n%100!=0&&n%4==0)) return 1; return 0;}int main(){ int year,month,day; while(~scanf("%d%d%d",&year,&month,&day)) { int sum=0; int f=judge(year); if(month*day==0||v[f][month-1]<day) {printf("illegal\n");continue;}//不合法 for(int i=1;i<year;i++) sum+=(judge(i)?366:365);//算出前n-1年的天数 for(int i=0;i<month-1;i++) sum+=v[f][i]; sum+=day;//再加上到这一天所经历的天数 printf("%s\n",ans[(sum-1)%7]); } return 0;}
0 0
- 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?
- 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 is it
- hdu 2133 What day is it
- What day is it 2133
- 杭电Hdu 2133 What day is it
- HDU 2133 What day is it(日期转换)
- hdu 1308 What Day Is It?
- hdoj 2133 What day is it
- 第14周项目3-多科成绩单-(3)
- C++11中的右值引用
- 快速排序
- ldconfig 命令
- Win32下使用公共控件库
- HDU 2133 What day is it
- 陈天桥或未完全退出盛大游戏
- iOS开发 - post / get 详解
- NLTK 学习笔记(4)
- ASCII与unicode
- Java当中的数组
- poj 3207 Ikki's Story IV - Panda's Trick
- XCode 快捷键, MAC 快捷键
- 14周项目6 读程序