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. TypeScript 素描 - 模块解析、声明合并

    模块解析 模块解析有两种方式 相对方式  也就是以/或 ./或-/开头的,比如import jq  from "/jq" 非相对方式  比如 import model  from ...

  2. go - 复合类型 array, slice, map

    Go 语言支持复合类型: 数组:array 切片:slice 指针:pointer 字典:map 通道:chan 结构体:struct 接口:interface 1. array   同一类型数据的集 ...

  3. Jquery面试题整合

    来自棱镜学院-在线IT教育     www.prismcollege.com 一.Jquery測试题 以下哪种不是jquery的选择器?(单选) A.基本选择器 B.后代选择器 C.类选择器 D.进一 ...

  4. [Python学习笔记][第八章Python异常处理结构与程序调试]

    1/30 第八章Python异常处理结构与程序调试 异常处理 try-except结构 try: try块 except Exception: except块 try-except-else结构 tr ...

  5. C#中DataGridView控件使用大全

    DataGridView 动态添加新行: DataGridView控件在实际应用中非常实用,特别需要表格显示数据时.可以静态绑定数据源,这样就自动为DataGridView控件添加相应的行.假如需要动 ...

  6. .net 导出

    public void CreateExcel(DataTable dt, string fileName) { HttpResponse resp = System.Web.HttpContext. ...

  7. iOS方法类:CGAffineTransform的使用

    CoreGraphics框架中的CGAffineTransform类可用于设定UIView的transform属性,控制视图的缩放.旋转和平移操作: 另称放射变换矩阵,可参照线性代数的矩阵实现方式0. ...

  8. java一点东西(3)

    运算符的优先级:()优先级最高 ! ++ -- 单目运算符 * / % + - > < <= >= == != && || 赋值符号 面向对象设计步骤:1.发现 ...

  9. 有向强连通分支Tarjan算法

    本文转载自:http://blog.csdn.net/xinghongduo/article/details/6195337 说到以Tarjan命名的算法,我们经常提到的有3个,其中就包括本文所介绍的 ...

  10. (原+转)Ubuntu下安装understand及在启动器中增加快捷方式

    参考网址: http://www.xuebuyuan.com/1353431.html http://www.2cto.com/os/201309/242543.html http://my.osch ...