杭电2133What day is it
来源:互联网 发布:淘宝客佣金 购物车 编辑:程序博客网 时间:2024/04/29 13:21
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号是周一,只需要求只一天离公元元年有多少天即可,注意题中所说“如果输入违法,请输出illegal”就因为这一句 贡献了三次wa.#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int i,n,j,k,l,leap,m,d,y;char s[8][100]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};//把日期存进字符数组 int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};//月份的天数存入数组 int run(int x){if((x%4==0&&x%100!=0)||x%400==0)return 1;//判断是否为闰年 return 0;}int main(){while(scanf("%d%d%d",&y,&m,&d)!=EOF){long sum=0;if(m==0||d==0||(m==2&&d>29)||(!((y%4==0&&y%100!=0)||y%400==0)&&m==2&&d>28)) { printf("illegal\n"); continue; }//如果日期非法 if(m==4||m==6||m==9||m==11) { if(d>30) { printf("illegal\n"); continue; } }//如果日期非法 if(m==1||m==3||m==5||m==7||m==8||m==10||m==12) { if(d>31) { printf("illegal\n"); continue; } }//如果日期非法 for(i=1;i<y;i++){if(run(i))sum=sum+366;elsesum=sum+365;}//判断到所输入的前一年离公元元年相差多少年 for(i=0;i<m-1;i++)sum=sum+a[i];//判断输入年份是当年的第几天 sum=sum+d;if(run(y)&&m>2)sum++;k=sum%7;//判断是周几. printf("%s\n",s[k]);}return 0;}
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
0 0
- 杭电2133What day is it
- 杭电 1308 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 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
- hdoj 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
- IOS LocationManager定位国内偏移,火星坐标(GCJ-02)解决方法
- egit push到gihub里提醒reject non - fast -forward
- 索引
- ConcurrentHashMap缓存
- ListView,图片,两行内容
- 杭电2133What day is it
- 汉诺塔(递归)
- 如何更快捷的设置Android Studio和Eclipse的快捷键一样和代码提示
- Ionic开发实战
- C++中的 explicit 关键字
- android接收从其他App传送来的数据
- 内存数据网格hazelcast的一些机制原理
- POJ 1837-Balance(01背包)
- Algorithms—240.Search a 2D Matrix II