B - Calendar

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Appoint description: 
System Crawler  (2015-05-23)

Description

Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows:

Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year.

In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.

Look at the sample to understand what borders are included in the aswer.

Input

The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 ≤ yyyy ≤ 2038 and yyyy:mm:dd is a legal date).

Output

Print a single integer — the answer to the problem.

Sample Input

Input
1900:01:01
2038:12:31
Output
50768
Input
1996:03:09
1991:11:12
Output
1579

题目大意:问你在这两个时间内有多少天。
#include<bits/stdc++.h>
using namespace std;
int LeapY[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int ULeapY[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int sum;
bool judge(int year){
if(year%400==0||(year%4==0&&year%100!=0))
return true;
return false;
}
int main(){
int i,yst,mst,dst,yen,men,den,stsum,tmp;
while(scanf("%d:%d:%d",&yst,&mst,&dst)!=EOF){
scanf("%d:%d:%d",&yen,&men,&den);
if(yst>yen){
swap(yst,yen);
swap(mst,men);
swap(dst,den);
}
else if(yst==yen){
if(mst>men){
swap(mst,men);
swap(dst,den);
}else if(mst==men){
if(dst>den){
swap(dst,den);
}
}
}
sum=stsum=0;
if(judge(yen)){
for(i=1;i<men;i++){
sum+=LeapY[i-1];
}
sum+=den;
}else{
for(i=1;i<men;i++){
sum+=ULeapY[i-1];
}
sum+=den;
}
if(judge(yst)){
for(i=1;i<mst;i++){
stsum+=LeapY[i-1];
}
stsum+=dst;
sum=sum+366-stsum;
}else{
for(i=1;i<mst;i++){
stsum+=ULeapY[i-1];
}
stsum+=dst;
sum=sum+365-stsum;
}
for(i=yst+1;i<yen;i++){
if(judge(i)){
sum+=366;
}else{
sum+=365;
}
}
if(yst==yen){
if(judge(yst)){
sum-=366;
}else{
sum-=365;
}
}
printf("%d\n",sum);
}
return 0;
}
/*
1999:03:02
1999:03:01
2000:03:03
2000:03:01 1999:03:05
1999:05:05 2000:03:05
2000:05:05 1999:01:01
1999:01:01 */

  

CF 304B——Calendar——————【年月日计算】的更多相关文章

  1. Gym 101206L Daylight Saving Time 根据年月日计算星期

    题意: [3月的第二个周日02:00:00 , 3月的第二个周日03:00:00) 这个区间都不是PST或PDT,[11月的第一个周日01:00:00 , 11月的第一个周日02:00:00) 这个区 ...

  2. 日期时间类:Date,Calendar,计算类:Math

    日期时间类 计算机如何表示时间? 时间戳(timestamp):距离特定时间的时间间隔. 计算机时间戳是指距离历元(1970-01-01 00:00:00:000)的时间间隔(ms). 计算机中时间2 ...

  3. 关于用Date类计算活了多少天和用Calendar类计算闰年的demo

    在javaSE阶段,Date类和Calendar类以后会经常用到 这两个类当中的一些常用方法 通过两个demo 进行学习和练习 第一个要求如下:让用户自己输入yyyy-MM-dd 格式的年月日 然后得 ...

  4. Android由出生年月日计算年龄(周岁)

    先从String类型的出生日期(“yyyy-MM-dd”)中提取int类型的年.月.日:再计算岁数. 程序如下: /** * 根据出生日期计算年龄的工具类BirthdayToAgeUtil */ pu ...

  5. java日期间相隔年月日计算

    /**     * 获取date1相距date2多少天, date2>date1     * @param date1     * @param date2     * @return     ...

  6. 08--MOOC--C/C++ 根据年月日计算星期几

    计算任何一天是星期几的几种算法 一:常用公式 W = [Y-1] + [(Y-1)/4] - [(Y-1)/100] + [(Y-1)/400] + D Y是年份数,D是这一天在这一年中的累积天数,也 ...

  7. 题目:利用Calendar类计算自己的出生日期距今天多少天,再将自己的出生日期利用SimpleDateFormat类设定的格式输出显示

    package cn.exercise; import java.util.Calendar; import java.util.Date; import java.text.SimpleDateFo ...

  8. An problem about date 根据年月日计算 星期几

    /W = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7(1.2月需要看作上一年的13.14月) #include<stdio.h> #include& ...

  9. C# 根据年月日计算周次

    //day:要判断的日期,WeekStart:1 周一为一周的开始, 2 周日为一周的开始 public static int WeekOfMonth(DateTime day, int WeekSt ...

随机推荐

  1. SQL server T-SQL索引详解

    SQL索引在数据库优化中占有一个非常大的比例,一个好的索引的设计,可以让sql语句查询效率提高很多被. 1.1 什么是索引? SQL索引有两种,聚集索引和非聚集索引,索引的主要目的是提高T-SQL系统 ...

  2. EF 配置实现建表与迁移

    通过EF 作为操作数据库的工具有一段时间了,也做了几个相对不大的项目,慢慢的也对EF的使用摸索出来了一些规则,虽然说不是技术难点,但是,我说的是但是,能够提高我们开发效率的棉花糖有时我们还是必须要吃的 ...

  3. 【bzoj4720】[Noip2016]换教室 期望dp+最短路

    Description 对于刚上大学的牛牛来说,他面临的第一个问题是如何根据实际情况申请合适的课程.在可以选择的课程中,有2n节 课程安排在n个时间段上.在第i(1≤i≤n)个时间段上,两节内容相同的 ...

  4. 【转】 spring context解惑

    转自:http://blog.csdn.net/c289054531/article/details/9196149?utm_source=tuicool&utm_medium=referra ...

  5. selenium滑动验证码操作

    1.首先要找到你要滑动的地方 2.调动鼠标事件按住不动 3.调整坐标即可 我这里是为了调试加了很多的sleep,print(hander)是为了看是否定位到了元素 4.效果如下图,但是我这里的验证文字 ...

  6. 模板【洛谷P3368】 【模板】树状数组 2

    P3368 [模板]树状数组 2 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的值 树状数组区间加,单点查询. code: #include <i ...

  7. swoole安装报错详解 mysqlnd_find_charset_nr in Unknow

    今天安装 swoole扩展时候,最后一步报错如下: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/m ...

  8. c#几种数据库的大数据批量插入(SqlServer、Oracle、SQLite和MySql)

    这篇文章主要介绍了c#几种数据库的大数据批量插入(SqlServer.Oracle.SQLite和MySql),需要的朋友可以了解一下. 在之前只知道SqlServer支持数据批量插入,殊不知道Ora ...

  9. Qt 学习之路 2(68):访问网络(4)

    Home / Qt 学习之路 2 / Qt 学习之路 2(68):访问网络(4) Qt 学习之路 2(68):访问网络(4) 豆子 2013年11月7日 Qt 学习之路 2 19条评论 前面几章我们了 ...

  10. 【Leetcode】Maximum Product Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...