hdu 2133 What day is it
来源:互联网 发布:tensorflow显卡要求 编辑:程序博客网 时间:2024/05/16 04:38
What day is it
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3506 Accepted Submission(s): 1034
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年1月1日(周六)天数差,然后模7就好,注意闰年还有合法性判断要包括0月和0日的情况。
#include<stdio.h>#include <string>#include <iostream>using namespace std;int mon[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}} ;int isleapyear(int year){ if((year%4==0 &&year%100!=0)||(year%400==0)) { return 1; } return 0;}int main( ){ int y,m,d; long long sum; while (cin>>y>>m>>d) { sum=0; if(m==0 || d==0 ||((!isleapyear(y)) && d>mon[0][m-1]) ||(isleapyear(y) && d>mon[1][m-1])) { cout<<"illegal"<<endl; continue; } for (int i=0; i<y; i++) { if(isleapyear(i)) { sum+=366; } else { sum+=365; } } for (int i=1; i<m; i++) { if(isleapyear(y)) { sum+=mon[1][i-1]; } else { sum+=mon[0][i-1]; } } sum+=d; switch (sum%7) { case 1: cout<<"Saturday"<<endl; break; case 2: cout<<"Sunday"<<endl; break; case 3: cout<<"Monday"<<endl; break; case 4: cout<<"Tuesday"<<endl; break; case 5: cout<<"Wednesday"<<endl; break; case 6: cout<<"Thursday"<<endl; break; case 0: cout<<"Friday"<<endl; break; } } 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
- csipsimple最新版本免编译在eclipse上成功运行
- shell中数学运算
- php学习笔记--全局变量,超全局变量
- 在centOS上安装oracle11g
- Android系统Recovery工作原理之使用update.zip升级过程分析(一)---update.zip包的制作
- hdu 2133 What day is it
- 性能调优攻略
- cordova 建立工程生成apk
- 微信号开发自定义分享到朋友圈
- IOS:屏幕旋转与Transform
- hdu 1498 50 years, 50 colors(最小顶点覆盖)
- windows 程序设计
- cocos2dx 检测是否点击到了图片的透明区域
- 由群发短信功能学习:CheckBox和ListView组合使用的方法和注意事项.