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日,满足以下一个条件的年份为闰年: ...
随机推荐
- C#关闭显示屏,使显示屏处于待机状态
class Program { private const uint WM_SYSCOMMAND = 0x112; //系统消息 private const int SC_MONITORPOWER = ...
- python之路-模块 WebDriver API
相关文档: http://selenium-python.readthedocs.org/en/latest/api.html#selenium.common.exceptions.InvalidEl ...
- 华为測试 字符串运用-password截取
Catcher是MCA国的情报员,他工作时发现敌国会用一些对称的password进行通信,比方像这些ABBA.ABA,A,123321,可是他们有时会在開始或结束时增加一些无关的字符以防止别国破解.比 ...
- Spark1.0.0 分布式环境搭建
软件版本号例如以下: Hostname IP Hadoop版本号 Hadoop 功能 系统 master 192.168.119.128 1.1.2 namenode jdk1.6+hadoop+sc ...
- markdown 书写代码
近期基于github + hexo 搭建了自己的博客.開始用markdown写博客,推荐 mac 平台用 mou 这个软件或者 vim. 介绍下markdown语法插入代码的规则: 有一种方法是全部代 ...
- ubuntu下30天自制操作系统还在继续学习中
操作系统还在学习中,进度不是非常确定,近期学习到了第13天的中部,由于把ucgui移植上去花了一点时间. 同一时候为了方便代码的兴许管理和分享,也为了学习github的代码管理使用思想, 所以建立了一 ...
- ios 自己定义导航栏和切割线
自己定义导航栏: // CustomNaviBarView.h #import <UIKit/UIKit.h> @interface CustomNaviBarView : UIView ...
- DBSNMP和SYSMAN用户初始密码及正确的修改方式
SYSMAN和DBSNMP跟涉及到Oracle的EM,所以跟其他的用户修改密码方式有所区别. 下面是这两个用户的默认密码和作用说明 DBSNMP DBSNMP The account used by ...
- 原生Javascript实现图片轮播效果
首先引入js运动框架 function getStyle(obj,name){ if(obj.currentStyle){ return obj.currentStyle[name]; } else{ ...
- 模板页 相对路径 JS 加载问题
问题:我在master页面中引入了如下js文件:<script type="text/javascript" src="http://www.cnblogs.com ...