Light 1414-February 29【容斥定理】
来源:互联网 发布:caffe loss值不变 编辑:程序博客网 时间:2024/04/29 21:47
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 between 2 * 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
Output for 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
Case 1: 1
Case 2: 0
Case 3: 1
Case 4: 3
Note
The names of the months are {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" and "December"}. And the numbers of days for the months are {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 and 31} respectively in a non-leap year. In a leap year, number of days for February is 29 days; others are same as shown in previous line.
#include<stdio.h>#include<string.h>#include<algorithm>#include<map> #include<string>using namespace std;map<string,int>mp;char month[20][25]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; bool judge(int y){if(y%400==0||(y%100!=0&&y%4==0))return true;return false;} int main(){for(int i=0;i<12;i++){mp[month[i]]=i+1;} int t,Q=1;scanf("%d",&t);while(t--){char ss[25];int m,y;int t1,t2;scanf("%s%d,%d",ss,&m,&y);if(judge(y)){if(mp[ss]>2)//第一个日期下不用考虑是不是包含2.29{y++;}}y--;t1=y/400-y/100+y/4;scanf("%s%d,%d",ss,&m,&y);if(judge(y)){if(mp[ss]>2||(mp[ss]==2&&m==29)){y++;}}y--;t2=y/400-y/100+y/4;printf("Case %d: %d\n",Q++,t2-t1);}return 0;}
- Light 1414-February 29【容斥定理】
- Light oj 1414 - February 29【容斥原理】
- 【Light OJ 1414】February 29(容斥原理)
- 【Light-oj】-1414 - February 29(容斥原理)
- Light OJ 1414 February 容斥
- Lightoj 1414 - February 29 (闰年统计,容斥定理)
- February 29 容斥定理 求闰年个数
- light oj 1414 - February 29
- Light OJ-----1414---February 29
- February 29 --容斥原理
- 【LightOJ】1414 - February 29(容斥原理)
- lightoj-1414-February 29【容斥原理&&细节】
- 数论 + 容斥定理
- HDU4407Sum 容斥定理
- uva11806(容斥定理)
- 容斥定理
- 容斥定理
- 容斥定理
- HDUT-2414-An interesting game(最小费用最大流)
- HDU 4552 怪盗基德的挑战书(kmp+dp)
- Unity基础 - 地形基础
- Java多线程编程----线程间通信--join()方法详解
- Android dialog 点击空白dialog不消失问题
- Light 1414-February 29【容斥定理】
- 程序无响应
- HTML&CSS——利用CSS定位背景图片 background-position
- AFNetworking汉化之“AFURLSessionManager”
- C# 引用DLL
- Django-- HttpResponse
- 玄学曲线并不玄 教你如何看懂GPU呈现
- 关于Action里面传值的问题
- 设计模式基本原则