D - D

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

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 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

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

题解:给两个日期,找在之间的2月29号的个数;wa了9次,所幸过了。。。

the second date will not represent a date which arrives earlier than the first date代表第二个日期比第一个大;

代码:

 #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 % == || (y % == && y % != ))
return true;
return false;
}
map<string, int>mp;
void init(){
mp["January"] = ;
mp["February"] = ;
mp["March"] = ;
mp["April"] = ;
mp["May"] = ;
mp["June"] = ;
mp["July"] = ;
mp["August"] = ;
mp["September"] = ;
mp["October"] = ;
mp["November"] = ;
mp["December"] = ;
}
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 - ) / + ;
t1 = (y - ) / + ;
t2 = (y - ) / + ;
return (t - t1 + t2);
}
int main(){
int N, kase = ;
char s1[], s2[];
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();
if(mp.count(s2)){
m2 = mp[s2];
}
else while();
// work(y1,y2,m1,m2,d1,d2);
if(y1 == y2){
if(rn(y1) && js(m1,d1, , ) && js(, , m2, d2)){
printf("Case %d: %d\n", ++kase, );
continue;
}
printf("Case %d: %d\n", ++kase, );
continue;
}
int t = find(y2 - ) - find(y1); if(rn(y1) && js(m1,d1, , ))t++;
if(rn(y2) && js(, , m2, d2))t++;
printf("Case %d: %d\n", ++kase, t);
}
return ;
}

February 29(模拟)的更多相关文章

  1. LightOJ 1414 February 29(闰年统计+容斥原理)

    题目链接:https://vjudge.net/contest/28079#problem/R 题目大意:给你分别给你两个日期(第二个日期大于等于第一个日期),闰年的2月29日称为闰日,让你求两个日期 ...

  2. hihocoder1148 February 29(区间闰年计数)

    hihocoder1148https://hihocoder.com/problemset/problem/1148 因为题目没有给范围,我本来是这么写的. ; i <= ; i++){ ==& ...

  3. 【9.29 模拟】T3 小清新最优化(easy)

    [题目描述] 给出一个长度为 n 的序列,序列的每个元素为一个二元组,代表一种单目运算: • \((0,x)\): 对于一个数\(a\),将其变为 \(a\&x\).\((\&=x)\ ...

  4. 6.29模拟赛 (T1:李时珍的皮肤衣 T2:马大嘴的废话 T3:SSY的队列 T4:清理牛棚);

    啊,又是考炸的一天,成功的退步了三名,啊,成共的看错了T1  的题意 ,水了80分. 第十五名就是我,额,已经有点倒数的感觉了,并且一道题都没AC  我太难了. 好了,废话不多说了,下面正式提接: 这 ...

  5. hihoCoder2月29日(字符串模拟)

    时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年: ...

  6. Lucky and Good Months by Gregorian Calendar - POJ3393模拟

    Lucky and Good Months by Gregorian Calendar Time Limit: 1000MS Memory Limit: 65536K Description Have ...

  7. poj3393[模拟题]

    Lucky and Good Months by Gregorian Calendar Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  8. Hihocoder 2月29日

      时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年 ...

  9. hihoCoder 1148 2月29日

    时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年: ...

随机推荐

  1. Direct3D 光照和材质

      今天我们来学习下Direct3D里面的光源和材质. 四大光照类型: 环境光 Ambient Light 一个物体没有被光照直接照射,通过每一些物体反射的光线到达这个物体,它也有可能被看到.这种称为 ...

  2. Coding.net代码托管空间申请与使用-安装并运行WordPress博客

    参考: http://www.freehao123.com/coding-net/ Coding.net这是一个国内新兴的代码托管平台,功能主要包括:代码托管.在线运行环境.监控代码质量,兼有一定的社 ...

  3. SQL:deferrable initially deferred

    SQL> create table cust(id number,name varchar2(10));Table created SQL> alter table cust add co ...

  4. [跟我学spring学习笔记][更多DI知识]

    延迟初始化Bean 定义: 延迟初始化也叫做惰性初始化,指不提前初始化Bean,在真正使用时才创建并初始化Bean 如何延迟: 配置方式很简单只需在标签上指定 “lazy-init” 属性值为“tru ...

  5. .NET中反射机制的使用与分析

    .NET中反射机制的使用与分析 [日期:2008-06-30] 来源:  作者:志伟     .NET反射的定义:审查元数据并收集关于它的类型信息的能力. 元数据是一种二进制信息,用以对存储在公共语言 ...

  6. 《JavaScript 闯关记》之原型及原型链

    原型链是一种机制,指的是 JavaScript 每个对象都有一个内置的 __proto__ 属性指向创建它的构造函数的 prototype(原型)属性.原型链的作用是为了实现对象的继承,要理解原型链, ...

  7. .NET AOP的实现

    一.AOP实现初步 AOP将软件系统分为两个部分:核心关注点和横切关注点.核心关注点更多的是Domain Logic,关注的是系统核心的业务:而横切关注点虽与核心的业务实现无关,但它却是一种更Comm ...

  8. enumerateObjectsUsingBlock VS for(... in ...)

    enumerateObjectsUsingBlock VS for(... in ...) for(... in ...)用起来非常方便.简洁,同时enumerateObjectsUsingBlock ...

  9. 类似QQ侧滑菜单功能实现

    之前的那文章简单实现了菜单侧拉功能,但是做不到像QQ那样导航条和tabBar一起移动...之后在网上找资料,有了思路,就自个写了个demo试试水. 先创建QHLMainController控制器,并把 ...

  10. 软件测试作业三 尝试使用JUnit

    写一个判断三角形种类的代码,对其进行测试. 判断三角形代码: package 测试1; public class sjx { public String f(int a,int b,int c) { ...