606第九周周三赛 E - What day is it今天星期几
2015-11-12 21:30
387 查看
E - What day is it
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice HDU
2133
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
其实我不太懂为什么不用考虑题目给的条件,难道0年1月1日是星期日吗?
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice HDU
2133
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
其实我不太懂为什么不用考虑题目给的条件,难道0年1月1日是星期日吗?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#include<stdio.h> #include<iostream> using namespace std; string a[7]= {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; int s[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31}; int IsLeap(int y) { if((y%4==0&&y%100!=0)||y%400==0) return 1; else return 0; } int judge(int y,int m,int d) { if(y>0&&y<10000&&m>0&&m<13&&d>0) { if(m==2) return d<=s[2]+IsLeap(y); else return d<=s[m]; } else return 0; } int day(int y,int m,int d) { int r=0; for(int i=1; i<y; i++) r+=365+IsLeap(i); s[2]+=IsLeap(y); for(int i=1; i<m; i++) r+=s[i]; s[2]=28; return r+d; } int main() { int y=0,m=0,d=0; while(scanf("%d%d%d",&y,&m,&d)!=EOF) { if(judge(y,m,d)==0) cout<<"illegal"<<endl; else { cout<<a[day(y,m,d)%7]<<endl; } } return 0; }
相关文章推荐
- codeforces-441B-Valera and Fruits【暴力】
- OFFICE2016仅安装需要的组件
- 闲谈在线订餐
- [11-17]作业小结
- nyoj--914--Yougth的最大化(二分查找)
- 94-《纪元2205》游戏体会.(2015.11.12)
- nyoj--914--Yougth的最大化(二分查找)
- 商业软件1班分组情况
- hdu5009Paint Pearls dp
- PostgreSQL学习手册(客户端命令<二>)
- RSA算法原理
- 归并排序(2-路)
- ASP.NET 页生命周期概述
- PostgreSQL学习手册(系统视图)
- JSP页面中的pageEncoding和contentType(charset)两种属性的区别
- Java中可变长参数的使用及注意事项
- iOS Autorelease的深入理解
- 3D图形技术术语汇总--openGL阅读总结
- PostgreSQL学习手册(系统表)
- python,学校成员类的例子,老师和学生(python class父类与子类之间的联系与逻辑)