http://acm.hdu.edu.cn/showproblem.php?pid=2133

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
 
时间复杂度:$O(1)$
代码:

#include <bits/stdc++.h>
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(~scanf("%d%d%d", &year, &month, &day)) {
if(IsRunNian(year)) {
if(day > a[month] || month == 0 || day == 0) {
printf("illegal\n");
continue;
}
} else{
if(day > b[month] || month == 0 || day == 0) {
printf("illegal\n");
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;
printf("%s\n",s[sum]);
}
return 0;
}

  

HDU 2133 What day is it的更多相关文章

  1. HDOJ(HDU) 2133 What day is it(认识下Java的Calendar类---日期类)

    Problem Description Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me wha ...

  2. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  3. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

  4. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  5. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  6. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. Nginx 负载均衡搭建

    配置文件Nginx/conf/nginx.conf 什么是负载均衡呢? 由于目前现有网络的各个核心部分随着业务量的提高,访问量和数据流量的快速增长,其处理能力和计算强度也相应地增大,使得单一的服务器设 ...

  2. IAP笔记

    1)   首先是IAP BootLoader程序设置:根据common.h里面的宏定义,设置BootLoader所占用的Flash空间. 2)   设置IAP UserApp程序设置:该型号Flash ...

  3. Python学习:7.文件操作

    文件操作 我们曾将听过一个问题,将大象放入冰箱分为三步:1.打开冰箱门,2.将大象放进去,3.关上冰箱门.今天我们要讲的Python文件操作的步骤就像将大象放入冰箱的步骤一样. 使用Python操作文 ...

  4. pyhton新手学习之增删改查

    一 .列表的定义 1.列表的定义     names = [ "xiajiqni", "test", "wangwu","oldb ...

  5. Git安装配置(Windows)

    下载Git并安装 下载地址:https://git-scm.com/ 安装一般默认即可 配置用户信息 配置之前最好已经有了Github的账号,如果没有可以先去注册一个 安装后打开Git Bash gi ...

  6. 优龙FS2410开发板学习过程遇到问题总结

    以下的问题及其解决办法是基于优龙FS2410开发板,不定期更新 ============================================================= 开发学习环境 ...

  7. Address already in use: JVM_Bind,tomcat启动异常

    严重: StandardServer.await: create[8050]: java.net.BindException: Address already in use: JVM_Bind tom ...

  8. 安装虚拟机以及ubuntu

    近期要用到linux,所以开始学习.想要在这里记录自己的学习之路 1.安装虚拟机以及装ubuntu系统 虚拟机就相当于一台电脑,电脑里得有系统,我们选择了ubuntu作为操作系统. 安装看下面的博客操 ...

  9. 「专题训练」Machine Schedule(HDU-1150)

    题意 在一个工厂,有两台机器\(A, B\)生产产品.\(A\)机器有\(n\)种工作模式(模式\(0\),模式\(1\)--模式\(n-1\)).\(B\)机器有\(m\)种工作模式(模式\(0\) ...

  10. MySQL数据库优化方法

    一.表类型MyISAM 和 InnoDB的区别 作者:Oscarwin链接:https://www.zhihu.com/question/20596402/answer/211492971来源:知乎著 ...