时间限制:2000ms
单点时限:1000ms
内存限制:256MB

描述

给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期)。

只有闰年有2月29日,满足以下一个条件的年份为闰年:

1. 年份能被4整除但不能被100整除

2. 年份能被400整除

输入

第一行为一个整数T,表示数据组数。

之后每组数据包含两行。每一行格式为"month day, year",表示一个日期。month为{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" , "December"}中的一个字符串。day与year为两个数字。

数据保证给定的日期合法且第一个日期早于或等于第二个日期。

输出

对于每组数据输出一行,形如"Case #X: Y"。X为数据组数,从1开始,Y为答案。

数据范围

1 ≤ T ≤ 550

小数据:

2000 ≤ year ≤ 3000

大数据:

2000 ≤ year ≤ 2×109

样例输入
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 本题涉及到求两个时段之间闰年的公式
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
bool isLeap(int y)
{
if((y%==&&y%!=)||y%==)
return true;
return false;
}
struct Date{
char mon[];
int day;
long long year;
Date()
{
memset(mon,,sizeof(mon));
}
};
Date Beg;
Date End;
LL Leaps(LL y)
{
return y/-y/+y/;
}
int main()
{
int T;
scanf("%d",&T);
int cas=;
while(cas<=T)
{
scanf("%s",Beg.mon);
scanf("%d,",&Beg.day);
scanf("%lld",&Beg.year);
scanf("%s",End.mon);
scanf("%d,",&End.day);
scanf("%lld",&End.year);
LL res=;
if(isLeap(Beg.year))
{
if(!strcmp("January",Beg.mon)||!strcmp("February",Beg.mon))
res++;
}
if(isLeap(End.year))
{
if(!strcmp("February",End.mon)&&End.day==||(strcmp("January",End.mon)!=&&strcmp("February",End.mon)!=))
{
res++;
}
}
if(End.year==Beg.year&&isLeap(Beg.year)&&isLeap(End.year))
res--;
if(End.year->Beg.year)
res+=(Leaps(End.year-)-Leaps(Beg.year));
printf("Case #%d: %lld\n",cas++,res);
} return ;
}

选一个基准日期,求两日期到基准日期距离的差。

#include <iostream>
#include <cstring>
using namespace std;
char month[][]={"Null","January","February","March","April","May","June","July", "August", "September", "October", "November","December"};
int d1,m1,y1;
int d2,m2,y2;
char mon1[],mon2[];
int sMon(char s[])
{
for(int i=;i<=;i++)
{
if(strcmp(month[i],s)==)
{
return i;
}
}
}
bool isLeap(int year)
{
if((year%==&&year%!=)||year%==)
{
return true;
}
return false;
}
int leaps(int year)
{
return year/-year/+year/;
}
int main()
{
int T;
cin>>T;
for(int cas=;cas<=T;cas++)
{
int lp1=;
int lp2=;
cin>>mon1>>d1;
cin.get();
cin>>y1;
cin>>mon2>>d2;
cin.get();
cin>>y2;
m1=sMon(mon1);
m2=sMon(mon2);
lp1+=leaps(y1-);
lp2+=leaps(y2-);
if(isLeap(y1))
{
if(m1>)
{
lp1++;
}
}
if(isLeap(y2))
{
if((m2==&&d2==)||m2>)
{
lp2++;
}
}
cout<<"Case #"<<cas<<": "<<lp2-lp1<<endl;
}
return ;
}

hihoCoder2月29日(字符串模拟)的更多相关文章

  1. 【hihoCoder】1148:2月29日

    问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...

  2. SQL点滴6—“微软不认识闰年2月29日”&字符"N"的作用

    原文:SQL点滴6-"微软不认识闰年2月29日"&字符"N"的作用 http://www.cnbeta.com/articles/50580.htm这个 ...

  3. Hihocoder 2月29日

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

  4. hihoCoder 1148 2月29日

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

  5. 数据可视化之DAX篇(一)Power BI时间智能函数如何处理2月29日的?

    https://zhuanlan.zhihu.com/p/109964336 ​今年是闰年,有星友问我,在Power BI中,2月29日的上年同期是怎么计算的? 这是个好问题,正好梳理一下,Power ...

  6. 2016年12月29日 星期四 --出埃及记 Exodus 21:24

    2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼, ...

  7. 2016年11月29日 星期二 --出埃及记 Exodus 20:20

    2016年11月29日 星期二 --出埃及记 Exodus 20:20 Moses said to the people, "Do not be afraid. God has come t ...

  8. 2016年10月29日 星期六 --出埃及记 Exodus 19:14

    2016年10月29日 星期六 --出埃及记 Exodus 19:14 After Moses had gone down the mountain to the people, he consecr ...

  9. 2016年6月29日 星期三 --出埃及记 Exodus 14:26

    2016年6月29日 星期三 --出埃及记 Exodus 14:26 Then the LORD said to Moses, "Stretch out your hand over the ...

随机推荐

  1. Oracle对没有主键的表分页

    普通情况对于有主键,能够做唯一表识的表.我们能够利用主键和rownum配合实现.比如: select scott.emp.* from scott.emp left join (select empn ...

  2. Eclipse 修改字符集

    Eclipse 修改字符集 默认情况下 Eclipse 字符集为 GBK,但现在很多项目采用的是 UTF-8,这是我们就需要设置我们的 Eclipse 开发环境字符集为 UTF-8, 设置步骤如下: ...

  3. NumPy事例练习

    因为排版问题直接把jupyter里的截图过来了:暂时就写了这么点小例子,建议在ipython notebook中做测试

  4. python--网络编程--socket

    网络通信标准---网络协议 互联网协议--osi七层协议 五层协议:应用层:应用层.表示层.会话层          传输层:传输层    网络层:网络层    数据链路层:数据链路层    物理层: ...

  5. linux 块设备驱动(四)——简单的sbull实例

    #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> # ...

  6. 关于CSS和CSS3的布局小知识(干货)

    最近在网站偶然看到的这个网站,进去看了下讲的CSS布局,感觉还不错,讲易懂且实用推荐给大家. http://zh.learnlayout.com/

  7. Linux快捷键和vim快捷键

    系统下常用快捷键   ctrl+左右键      在单词之间跳转 Ctrl + a            光标移动到行首(ahead of line),相当于通常的Home键 Ctrl + e     ...

  8. Appium python自动化测试系列之Capability介绍(五)

    ​5.1 Capability介绍 5.1.1 什么是Capability 在讲capability之前大家是否还记得在讲log时给大家看过的启动时的日志?在我们的整个启动日志中会出现一些配置信息,其 ...

  9. Webkit二:RenderTree 创建

    RenderObject 作为所有Render 树节点的基类,完全类似与DOM树中的Node基类,它是构成Render 树的基础,作用非比寻常,其中包含了构成Render 树所可能涉及到的一些基本属性 ...

  10. 平滑的滚动listview到一个指定位

    http://blog.csdn.net/w8320273/article/details/9043339