February 29(模拟)
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(模拟)的更多相关文章
- LightOJ 1414 February 29(闰年统计+容斥原理)
题目链接:https://vjudge.net/contest/28079#problem/R 题目大意:给你分别给你两个日期(第二个日期大于等于第一个日期),闰年的2月29日称为闰日,让你求两个日期 ...
- hihocoder1148 February 29(区间闰年计数)
hihocoder1148https://hihocoder.com/problemset/problem/1148 因为题目没有给范围,我本来是这么写的. ; i <= ; i++){ ==& ...
- 【9.29 模拟】T3 小清新最优化(easy)
[题目描述] 给出一个长度为 n 的序列,序列的每个元素为一个二元组,代表一种单目运算: • \((0,x)\): 对于一个数\(a\),将其变为 \(a\&x\).\((\&=x)\ ...
- 6.29模拟赛 (T1:李时珍的皮肤衣 T2:马大嘴的废话 T3:SSY的队列 T4:清理牛棚);
啊,又是考炸的一天,成功的退步了三名,啊,成共的看错了T1 的题意 ,水了80分. 第十五名就是我,额,已经有点倒数的感觉了,并且一道题都没AC 我太难了. 好了,废话不多说了,下面正式提接: 这 ...
- hihoCoder2月29日(字符串模拟)
时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年: ...
- Lucky and Good Months by Gregorian Calendar - POJ3393模拟
Lucky and Good Months by Gregorian Calendar Time Limit: 1000MS Memory Limit: 65536K Description Have ...
- poj3393[模拟题]
Lucky and Good Months by Gregorian Calendar Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- Hihocoder 2月29日
时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年 ...
- hihoCoder 1148 2月29日
时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期). 只有闰年有2月29日,满足以下一个条件的年份为闰年: ...
随机推荐
- Top 15 Tools To Make Animated GIFs From Images & Video
Creating an animated GIF picture from photos or video with Adobe Photoshop is easy, but not everyone ...
- UIButton-初识IOS
今天,我学到了所有app经常用到的UIButton控件,废话不多说,这些都是我学习的时候总结的一些,希望可以帮到以后的初学者,IOS初学不应该直接拖拽,感觉不易于理解,所以我总结的基本上全是纯代码编辑 ...
- WPF窗体属性
以后慢慢加吧! ResizeMode="NoResize" 禁止缩放大小 WindowStyle="ToolWindow" 隐藏最大化与最小化按钮WindowS ...
- JavaScript ----------- 组合继承
继承 实现继承:继承实际的方法.ECMAScript 只支持实现继承,而且其实现基础主要是依靠原型链来实现的. 基本思想是:利用原型来实现一个引用类型继承另外一个引用类型的属性和方法. 原型 - 构造 ...
- JavaBean和EJB的区别
首先,EJB是指运行在EJB容器中的JavaBean.Tomcat是Web容器的参考实现.一个完整的JavaEE服务器应该包括Web容器和EJB容器.其次,Web容器中无法运行EJB,同时所有的Jav ...
- SpringMvc学习-增删改查
本节主要介绍SpringMVC简单的增删改查功能. 1.查询 dao中的代码 public List<WeatherPojo> getAllWeather(){ String sql=&q ...
- .NET的 DataTable中某列求和
public DataTable ReportDetail { get; set; }//定义datatable属性 this.txtTotalPiece.Text = ReportDetail.Co ...
- [uva11916] Emoogle Grid (离散对数)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Emoogle Grid You have to color an MxN ( ...
- 【面向代码】学习 Deep Learning(三)Convolution Neural Network(CNN)
========================================================================================== 最近一直在看Dee ...
- jquery的使用 超级快速入门 熟练使用
如何使用jquery,首先需要引入jquery的js库文件,可以是免费的cdn资源,也可以是本地下载的资源 使用方法:$(function(){ 这里面写你要执行的代 ...