时间限制: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. window.open 打开子窗体,关闭全部的子窗体

    需求:通过window.open方法打开了子窗体,当关闭主窗体时.子窗体应当也关闭. 实现思路: 1.打开子窗体函数window.open(url,winName)的第二个參数winName能够唯一标 ...

  2. Laravel 设置语言不生效的问题

    使用了validate 验证,提示错误默认是 英文的.将en 改为zh-CN 后 运行 composer require "overtrue/laravel-lang:~3.0"时 ...

  3. ffmpeg H264 编解码配置

    ffmpeg H264编解码前面有文章介绍下,本文主要介绍一些参数配置. 编码: int InitEncoderCodec( int iWidth, int iHeight) { AVCodec * ...

  4. 【HDOJ 5371】 Hotaru&#39;s problem

    [HDOJ 5371] Hotaru's problem Manacher算法+穷举/set Manacher算法一好文:http://blog.csdn.net/yzl_rex/article/de ...

  5. C++入门一

    C++ 项目结构 Resource Files: 项目引用的位图文件,图标,窗口,光标等.比如,你的程序要生成一个exe文件,而文件的图标是你自定义的图标,那就要在这个工程里面添加Icon资源,添加一 ...

  6. Redhat 6.2安装Oracle 11gclient及遇到的问题分析

    昨天在Redhat6.2(64 bit)上安装oracle 11.2.0.1.0 client(32 bit),下面是安装中碰到的一些问题及处理过程记录 首先解压缩安装包,会生成一个client文件夹 ...

  7. 再过半小时,你就能明白kafka的工作原理了

    本文在个人技术博客不同步发布,详情可猛戳 亦可扫描屏幕右侧二维码关注个人公众号,公众号内有个人联系方式,等你来撩... 为什么需要消息队列 周末无聊刷着手机,某宝网APP突然蹦出来一条消息" ...

  8. 关于angular JS 中$timeOut 的一些不正常情况下的$destory

    最近项目中存在的问题头疼脑热了好一会. 我先简单说明下问题是由,使用$timeOut循环调用的时候由于页面存在异步加载会出现反复执行循环反复调用$timeOut,怎么清除跳出循环都不管用.于是查到了如 ...

  9. HDU 5313 Bipartite Graph(二分图染色+01背包水过)

    Problem Description Soda has a bipartite graph with n vertices and m undirected edges. Now he wants ...

  10. EasyDarwin开源流媒体项目

    本文转自EasyDarwin CSDN官方博客:http://blog.csdn.net/easydarwin EasyDarwin是由国内开源流媒体团队维护和迭代的一整套开源流媒体视频平台框架,从2 ...