LightOJ - 1414 February 29 (日期模拟)有多少个2月29
来源:互联网 发布:日本转区软件 编辑:程序博客网 时间:2024/04/30 17:05
SubmitStatus
Description
It is 2012, and it's a leap year. So there is a "February 29" in this year, which is called leap day. Interesting thing is the infant who will born in this February 29, will get his/her birthday again in 2016, which is another leap year. So February 29 only exists in leap years. Does leap year comes in every 4 years? Years that are divisible by 4 are leap years, but years that are divisible by 100 are not leap years, unless they are divisible by 400 in which case they are leap years.
In this problem, you will be given two different date. You have to find the number of leap days in between them.
Input
Input starts with an integer T (≤ 550), denoting the number of test cases.
Each of the test cases will have two lines. First line represents the first date and second line represents the second date. Note that, the second date will not represent a date which arrives earlier than the first date. The dates will be in this format - "month day, year", See sample input for exact format. You are guaranteed that dates will be valid and the year will be in between2 * 103 to 2 * 109. For your convenience, the month list and the number of days per months are given below. You can assume that all the given dates will be a valid date.
Output
For each case, print the case number and the number of leap days in between two given dates (inclusive).
Sample Input
4
January 12, 2012
March 19, 2012
August 12, 2899
August 12, 2901
August 12, 2000
August 12, 2005
February 29, 2004
February 29, 2012
Sample Output
Case 1: 1
Case 2: 0
Case 3: 1
Case 4: 3
Hint
Source
#include<cstdio>#include<set>#include<queue>#include<cstring>#include<algorithm>#include<map>#include<string>using namespace std;bool js(int y,int r, int yy, int rr){if(y < yy)return true;if(y > yy)return false;if(r <= rr)return true;return false;}bool rn(int y){if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))return true;return false;}map<string, int>mp;void init(){mp["January"] = 1;mp["February"] = 2;mp["March"] = 3;mp["April"] = 4;mp["May"] = 5;mp["June"] = 6;mp["July"] = 7;mp["August"] = 8;mp["September"] = 9;mp["October"] = 10;mp["November"] = 11;mp["December"] = 12;}void work(int &y1,int &y2,int &m1,int &m2,int &d1,int &d2){if(y1 > y2){swap(y1,y2);swap(m1,m2);swap(d1,d2);return;}if(y1 < y1){return;}if(m1 > m2){swap(y1,y2);swap(m1,m2);swap(d1,d2);return;}if(m1 < m2){return;}if(d1 > d2){swap(y1,y2);swap(m1,m2);swap(d1,d2);return;}}int find(int y){int t, t1, t2;t = (y - 2000) / 4 + 1;t1 = (y - 2000) / 100 + 1;t2 = (y - 2000) / 400 + 1;return (t - t1 + t2);}int main(){int N, kase = 0;char s1[15], s2[15];int y1, d1, y2, d2, m1, m2;scanf("%d", &N);init();while(N--){scanf("%s%d,%d", s1, &d1, &y1);scanf("%s%d,%d", s2, &d2, &y2);if(mp.count(s1)){m1 = mp[s1];}else while(1);if(mp.count(s2)){m2 = mp[s2];}else while(1);if(y1 == y2){if(rn(y1) && js(m1,d1, 2, 29) && js(2, 29, m2, d2)){printf("Case %d: %d\n", ++kase, 1);continue;}printf("Case %d: %d\n", ++kase, 0);continue;}int t = find(y2 - 1) - find(y1);if(rn(y1) && js(m1,d1, 2, 29)) t++;if(rn(y2) && js(2, 29, m2, d2)) t++;printf("Case %d: %d\n", ++kase, t);}return 0;}
- LightOJ - 1414 February 29 (日期模拟)有多少个2月29
- Lightoj 1414 - February 29
- lightoj 1414 February 29
- 【Lightoj 1414 - February 29 】
- lightoj 1414 - February 29
- LightOJ-1414-February 29--总共多少个闰日?--两种解法
- LightOj 1414 1414 - February 29
- LIGHTOJ 1414 - February 29【Leap】
- 统计起始日期之间有多少个2月29日
- 【LightOJ】1414 - February 29(容斥原理)
- Lightoj 1414 - February 29 (闰年统计,容斥定理)
- lightoj-1414-February 29【容斥原理&&细节】
- 2个日期之间有多少天
- mysql 计算两个日期间有多少个2月29
- 判断2个日期之间相差多少个月
- LCS(模拟,寻找有多少个循环)
- Lingt oj 1414 - February 29
- light oj 1414 - February 29
- isapi_redirect.exe安装失败处理
- 微信公众号第三方开发之四回调url中获取授权方的授权信息以及基本信息
- Linux rpm命令教程
- [递推递归] 集合的划分
- 增量更新——新兴的一种更新方式
- LightOJ - 1414 February 29 (日期模拟)有多少个2月29
- POJ-1724-ROADS(优先队列,邻接表,BFS)
- hdoj 1078 FatMouse and Cheese 【dp】
- java 基本数据类型及自动类型提升
- 用Latex写伪代码
- web兼容性及解决方案(收集)
- 1043. 输出PATest(20)
- 动态规划理论思想
- const