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. hdu 5256 序列变换(LIS最长上升子序列)

    Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数. 请输出最少需要修改多 ...

  2. 使用 Microsoft.ApplicationBlocks.Data SqlHelper 查询超时以及解决方案

     提示: 后面附有文件,不喜欢看吐槽的,直接到文章结尾下载 摘要:Data Access Application Block 是一个 .NET 组件,包含优化的数据访问代码,可以帮助用户调用存储过程以 ...

  3. Highcharts 非常实用的Javascript统计图

    Highcharts 官网: http://www.highcharts.com Highcharts 官网示例:http://www.highcharts.com/demo/ Highcharts ...

  4. ABAP - 日期格式转换 &amp; ABAP经常使用日期处理函数

    ABAP - 日期格式转换 如今提供下面一些日期格式转换的函数: Below are several FMs which can be used to convert date format. 1. ...

  5. [Regex Expression] Tagline --- {0, } {1,10}

    Using a character set repeated 1 or more times, make a pattern to search for strings that do not con ...

  6. UISegmentedControl判断点击第几项

    UISegmentedControl 关于UISegmentedControl判断当前点击的是第几项,找了很久,终于再老外的博客上找到了,在委托中 UISegmentedControl *Seg=se ...

  7. oracle 临时表空间的增删改查

    oracle 临时表空间的增删改查 oracle 临时表空间的增删改查 1.查看临时表空间 (dba_temp_files视图)(v_$tempfile视图)select tablespace_nam ...

  8. mysql的join

    SELECT * FROM a LEFT JOIN b ON a.aID = b.bID;  a为主,a的数据全显示,连不上b的对应字段为空   SELECT * FROM a RIGHT JOIN ...

  9. 深入C语言内存区域分配(进程的各个段)详解(转)

    原文地址:http://www.jb51.net/article/39696.htm 一般情况下,一个可执行二进制程序(更确切的说,在Linux操作系统下为一个进程单元,在UC/OSII中被称为任务) ...

  10. stl学习之模板

    模板是实现代码重用机制的一种工具,实质就是实现类型参数化,即把类型定义为参数. C++提供两种模板:函数模板,类模板.   template<typename T> //或者 templa ...