时间限制: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. [Algorithms] Refactor a Loop in JavaScript to Use Recursion

    Recursion is when a function calls itself. This self calling function handles at least two cases, th ...

  2. poj 2528(区间改动+离散化)

    题意:有一个黑板上贴海报.给出每一个海报在黑板上的覆盖区间为l r,问最后多少个海报是可见的. 题解:由于l r取值到1e7,肯定是要离散化的,但普通的离散化会出问题.比方[1,10],[1,4],[ ...

  3. jquery 的父子节点

    1.一级父节点 parent() n级父节点 parents(???). 2.一级子节点 children() n级子节点  用find(???)

  4. vs附加到多个进程调试

    我们用vs调试,通常附加到一个进程进行调试,有时候需要同时附加到多个进程. 例如:同时调试客户端与服务端,我们需要同时附加到客户端与服务端进程. 按F5(执行)键调试,程序只要遇到断点就中断. 按F1 ...

  5. xcode 5.0 以上去掉icon高亮方法&amp;iOS5白图标问题

    之前的建议方法是把在xxx.info.plist文件里把 icon already includes gloss and bevel effects 设置YES 在Xcode5下,重复实现不成功,今天 ...

  6. mysql 修改表引擎方法

    修改表引擎方法 方法1:修改mysql.ini配置文件,重启mysql服务生效 修改my.ini,在[mysqld]下加上default-storage-engine=INNODB 其中红色字体部分是 ...

  7. 【Sprint3冲刺之前】项目完成时间表

    Sprint2冲刺成果——项目完成时间表 项目完成时间表 经过Sprint2小组总结会议的探讨,我们决定一起约定项目alpha版本,beta版本,release版本的发布时间,发布形式及预计完成效果 ...

  8. Linux kernel Wikipedia

    http://en.wikipedia.org/wiki/Linux_kernel Development model The current development model of the Lin ...

  9. iOS之简单瀑布流的实现

    iOS之简单瀑布流的实现   前言 超简单的瀑布流实现,这里说一下笔者的思路,详细代码在这里. 实现思路 collectionView能实现各中吊炸天的布局,其精髓就在于UICollectionVie ...

  10. android mvp高速开发框架介绍(dileber的简单介绍)

    今天我为大家介绍一款android mvp框架:dileber(https://github.com/dileber/dileber.git) 官方交流qq群:171443726 我个人qq:2971 ...