日期之差
来源:互联网 发布:交管12123一直网络失败 编辑:程序博客网 时间:2024/05/10 14:16
日期之差
问题描述
已知2011年11月11日是星期五,问YYYY年MM月DD日是星期几?注意考虑闰年的情况。尤其是逢百年不闰,逢400年闰的情况。
输入格式
输入只有一行
YYYY MM DD
YYYY MM DD
输出格式
输出只有一行
W
W
数据规模和约定
1599 <= YYYY <= 2999
1 <= MM <= 12
1 <= DD <= 31,且确保测试样例中YYYY年MM月DD日是一个合理日期
1 <= W <= 7,分别代表周一到周日
1 <= MM <= 12
1 <= DD <= 31,且确保测试样例中YYYY年MM月DD日是一个合理日期
1 <= W <= 7,分别代表周一到周日
样例输入
2011 11 11
样例输出
5
#include <iostream>#include <cstdio>using namespace std;bool isLeapYear(int);int getMaxday(int ,int ); typedef struct DATE{int year;int month;int day;void nextDay(){day++;if(day > getMaxday(year,month)){day = 1;month++;if(month > 12){month = 1;year++;}}}bool operator < (const DATE &b)const{if(year != b.year) return year < b.year;if(month != b.month) return month < b.month;if(day != b.day) return day < b.day;}bool operator !=(const DATE &b)const {return year != b.year || month != b.month || day != b.day;} }Date; //判断闰年 bool isLeapYear(int year){return year % 400 == 0 || year % 4 == 0 && year % 100 != 0;}//获得该年该月的最大天数 int getMaxday(int year,int month){switch(month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 4:case 6:case 9:case 11:return 30;case 2:return isLeapYear(year)? 29: 28;default:return -1;}}int main(){Date d1,d2;d1.year = 2011;d1.month = 11;d1.day = 11;while(scanf("%d%d%d",&d2.year,&d2.month,&d2.day) != EOF){if(d2 < d1){Date tmp = d1;d1 = d2;d2 = tmp;}int days = 0;while(d1 != d2){d1.nextDay();days++;}int w = 0;w= ((days + w) % 7 + 4) % 7 + 1;printf("%d\n",w);}return 0;}
1 0
- 日期之差
- 日期之差
- oracle算日期之差
- informix 计算 日期之差
- js 两个日期之差
- Java_日期操作_日期之差
- JS计算日期天数之差
- JS DATE 计算两个日期之差
- 计算两个日期的天数之差
- 求两个日期之差 C/C++
- ios开发之 时间日期差计算
- DateTimePicker之格式化年月日&计算日期差
- 日期差
- 日期差
- 日期差
- 日期差
- 日期差
- 日期、时间戳互相转换、日期之差
- 区间查询(树状数组之差点问线问题)
- php文件管理系统
- HTML中position的五种属性值
- ubuntu下安装JDK
- 实战ArduinoUNO制作高压编程器恢复Atmega8熔丝
- 日期之差
- 数据学习---数据结构1
- 语音识别工具箱之kaldi介绍
- Linux系统VNC配置实践总结
- android圆形的View控件
- from nova to ironic(4)
- First calibration example - Corner extraction, calibration, additional tools (三)
- ORACLE优化器RBO与CBO介绍总结
- 【万里征程——Windows App开发】ListView&GridView之添加数据