Light OJ-----1414---February 29

February 29

Time Limit: 1 second(s)Memory Limit: 32 MB

It is 2012, and it's a leap year. So there is a "February29" in this year, which is called leap day. Interesting thing is theinfant who will born in this February 29, will get his/her birthday again in2016, 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 leapyears, but years that are divisible by 100 are not leap years, unless they aredivisible by 400 in which case they are leap years.

In this problem, you will be given two different date. Youhave 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 linerepresents the first date and second line represents the second date. Notethat, the second date will not represent a date which arrives earlier than thefirst date. The dates will be in this format - "month day, year",See sample input for exact format. You are guaranteed that dates will be validand the year will be in between 2 * 103 to 2 * 109.For your convenience, the month list and the number of days per months aregiven 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 leapdays 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


给定两个年月日,题目说是判定多少闰年,实际是判定两日期之间有多少个2月29

两端点整除4判定闰年,再减去整除100的非闰年,再加上整除400的闰年,最后特判端点

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 5e5+10;
const int MOD = 1e9+7; 
char s[50], str[50];
int main(){  
    LL t, a, b, x, y, kcase = 1;
    scanf("%lld", &t);
    while(t--){
    	scanf("%s%lld, %lld", s, &a, &b);
    	scanf("%s%lld, %lld", str, &x, &y);
    	LL ans = y/4 - y/100 + y/400;
    	ans -= b/4 - b/100 + b/400;
    	if(b%4 == 0 && b%100 != 0 || b % 400 == 0){
    		if((s[0] == 'J' && s[1] == 'a') || s[0] == 'F') ans++;
		}
    	if(y%4 == 0 && y%100 != 0 || y%400 == 0){
    		if((str[0] == 'J' && str[1] == 'a') || (str[0] == 'F' && x < 29)) ans--;
		}
		printf("Case %lld: %lld\n", kcase++, ans);
	}
    return 0;  
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值