hihoCoder2月29日(字符串模拟)
描述
给定两个日期,计算这两个日期之间有多少个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日(字符串模拟)的更多相关文章
- 【hihoCoder】1148:2月29日
问题:http://hihocoder.com/problemset/problem/1148 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 思路: 1. 将问题转换成求两个日 ...
- SQL点滴6—“微软不认识闰年2月29日”&字符"N"的作用
原文:SQL点滴6-"微软不认识闰年2月29日"&字符"N"的作用 http://www.cnbeta.com/articles/50580.htm这个 ...
- Hihocoder 2月29日
时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年 ...
- hihoCoder 1148 2月29日
时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年: ...
- 数据可视化之DAX篇(一)Power BI时间智能函数如何处理2月29日的?
https://zhuanlan.zhihu.com/p/109964336 今年是闰年,有星友问我,在Power BI中,2月29日的上年同期是怎么计算的? 这是个好问题,正好梳理一下,Power ...
- 2016年12月29日 星期四 --出埃及记 Exodus 21:24
2016年12月29日 星期四 --出埃及记 Exodus 21:24 eye for eye, tooth for tooth, hand for hand, foot for foot,以眼还眼, ...
- 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 ...
- 2016年10月29日 星期六 --出埃及记 Exodus 19:14
2016年10月29日 星期六 --出埃及记 Exodus 19:14 After Moses had gone down the mountain to the people, he consecr ...
- 2016年6月29日 星期三 --出埃及记 Exodus 14:26
2016年6月29日 星期三 --出埃及记 Exodus 14:26 Then the LORD said to Moses, "Stretch out your hand over the ...
随机推荐
- phonegap工程中修改app的名字
针对phonegap比较高的版本,我的是6.4.0. 在phonegap工程中,当添加了iOS和android平台或多个平台后,工程进行了开发,然后觉得app的名字想修改一下(比如在手机上显示的app ...
- 重温.NET下Assembly的加载过程 ASP.NET Core Web API下事件驱动型架构的实现(三):基于RabbitMQ的事件总线
重温.NET下Assembly的加载过程 最近在工作中牵涉到了.NET下的一个古老的问题:Assembly的加载过程.虽然网上有很多文章介绍这部分内容,很多文章也是很久以前就已经出现了,但阅读之后 ...
- Codeforces 569 B. Inventory
click here~~ **B. Inventory** time limit per test1 second memory limit per test256 megabytes inputst ...
- 华为P7电信4G版刷机包 EMUI2.3 官方B125 第3版 精简 ROOT
ROM介绍 基于底包至 B125 SP03解包制作 增加自己订制的超美丽EMUI 2.3专用的全局主题 自调刷机脚本,全部权限完美百分百与官方原版相贴合. 加入Root权限并使用SuperSU 2.0 ...
- MySQL提示Access denied for user ''@'localhost'”的解决
记得那时由于没有网络,把rootpassword改错了写成了: update user set password="122" where user="root" ...
- OpenCV load 运行出错 cv::Exception 出错
今天在使用OpenCV的load函数时,出现错误,代码如下: cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 ); ...
- mysql 数据类型+约束+关联
1.什么是存储引擎存储引擎就是表的类型,针对不同的存储引擎,mysql会有不同的处理逻辑 2.存储引擎介绍InnoDB| DEFAULT | Supports transactions, row-le ...
- A20 烧录和启动 log
用 LiveSuit 烧写了一个 lubuntu 的映像文件到板子上, 同时接了串口观察烧录过程的串口打印信息, 如下 ES: FES:Fes Ver: 098 FES:=============== ...
- JSP学习笔记(一)
JSP是基于JAVA语言的,区分大小写,HTML不区分大小写 如何建立Web服务目录? 1.在Webapps下面建立Web服务目录MYJSP 在Webapps下面新建文件夹MYJSP,将写好的jsp文 ...
- 手机QQ后台清理不掉的秘密——anddroid悬浮窗
问题来自于一篇文章:手机QQ后台为何清不掉?MIUIproject师:全靠1像素的页面保命 出于好奇,想知道这一像素究竟是啥东西,用手机安全管家控制QQ的悬浮窗权限: 关闭QQ的悬浮窗权限,通过后台一 ...