CF 304B——Calendar——————【年月日计算】
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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
1900:01:01
2038:12:31
50768
1996:03:09
1991:11:12
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",¥,&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——————【年月日计算】的更多相关文章
- Gym 101206L Daylight Saving Time 根据年月日计算星期
题意: [3月的第二个周日02:00:00 , 3月的第二个周日03:00:00) 这个区间都不是PST或PDT,[11月的第一个周日01:00:00 , 11月的第一个周日02:00:00) 这个区 ...
- 日期时间类:Date,Calendar,计算类:Math
日期时间类 计算机如何表示时间? 时间戳(timestamp):距离特定时间的时间间隔. 计算机时间戳是指距离历元(1970-01-01 00:00:00:000)的时间间隔(ms). 计算机中时间2 ...
- 关于用Date类计算活了多少天和用Calendar类计算闰年的demo
在javaSE阶段,Date类和Calendar类以后会经常用到 这两个类当中的一些常用方法 通过两个demo 进行学习和练习 第一个要求如下:让用户自己输入yyyy-MM-dd 格式的年月日 然后得 ...
- Android由出生年月日计算年龄(周岁)
先从String类型的出生日期(“yyyy-MM-dd”)中提取int类型的年.月.日:再计算岁数. 程序如下: /** * 根据出生日期计算年龄的工具类BirthdayToAgeUtil */ pu ...
- java日期间相隔年月日计算
/** * 获取date1相距date2多少天, date2>date1 * @param date1 * @param date2 * @return ...
- 08--MOOC--C/C++ 根据年月日计算星期几
计算任何一天是星期几的几种算法 一:常用公式 W = [Y-1] + [(Y-1)/4] - [(Y-1)/100] + [(Y-1)/400] + D Y是年份数,D是这一天在这一年中的累积天数,也 ...
- 题目:利用Calendar类计算自己的出生日期距今天多少天,再将自己的出生日期利用SimpleDateFormat类设定的格式输出显示
package cn.exercise; import java.util.Calendar; import java.util.Date; import java.text.SimpleDateFo ...
- 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& ...
- C# 根据年月日计算周次
//day:要判断的日期,WeekStart:1 周一为一周的开始, 2 周日为一周的开始 public static int WeekOfMonth(DateTime day, int WeekSt ...
随机推荐
- webservice不能序列化接口问题,返回值为IList或者参数为接口的解决办法。
1. webservice 不能返回泛型接口集合IList,解决办法如下链接: 参考资料:http://www.cnblogs.com/yinhaiming/articles/1379424.html ...
- 跳转iPhone设置页面,绕过审核
1.问题描述 跳转iPhone设置页面之前都是通过 App-Prefs:root=WIFI 来跳转,但是2018年6月废弃了这个函数,被认为是私有函数,审核会被拒绝. 有心人采用了字符串转码的方式来规 ...
- MVC进阶篇(一)——概览
前言 说到MVC,就得先说说框架是什么东西,MVC好多人都知道,是Model.view.controller,但是MVC到底是什么样的一个框架呢,好多人又说了是约定大于配置.下面我来说说我的理解. 内 ...
- 【spring】bean加载顺序
问题来源 有一个bean为A,一个bean为B.想要A在容器实例化的时候的一个属性name赋值为B的一个方法funB的返回值. 如果只是在A里单纯的写着: private B b; private S ...
- iframe里面的元素触发父窗口元素事件的jquery代码 转
例如父窗口定义了一个事件. top: $(dom1).bind('topEvent', function(){}); 那么iframe里面的元素怎样触发父窗口dom1的事件呢?这样吗? $(dom1, ...
- Could not get lock /var/lib/apt/lists/lock
执行: apt-get update 出现 Could not get lock /var/lib/apt/lists/lock 解决办法: 查询与apt相关的进程 ps -e | grep apt ...
- linux下使用文件IO监听GPIO中断
完整的程序如下: #include<stdlib.h> #include<stdio.h> #include<string.h> #include<unist ...
- CentOS 7 系统区域和键盘设置
系统区域设置包括语言.键盘布局等,可以通过修改/etc/locale.conf配置文件或使用localectl实用程序来进行设置,一般在安装时设置为默认选择(英文.美式键盘)即可 修改配置文件 [ro ...
- python xlwt 与 xlsxwriter 模块差别
Xlwt 模块有一个bug, 就是所用样式过多的话,之后的数据将使用不了样式,相反xlsxwriter 模块 不会有此问题. 用Xlwt模块的同学们,请务必转换用xlsxwriter模块 !!!!!! ...
- 1001 害死人不偿命的(3n+1)猜想 (15 分)
#include <iostream> using namespace std; int main(){ ; cin >> n; ){ != ) n = ( * n + ) / ...