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 ...
随机推荐
- Xcode打包提交至itunes connect后,提交审核成功,随后出现二进制文件无效
1.问题描述 Xcode打包提交至itunes connect后,提交审核成功,应用处于待审核状态,过了大概半个小时状态更改为二进制文件无效 2.原因分析 2.1 登陆在苹果中预留的邮箱 ---- 邮 ...
- 解决org.hibernate.NonUniqueObjectException的问题
不知道是不是之前处理懒加载的问题对session工厂进行了处理,导致了之前没有问题的地方出现了错误. 当修改班级操作时出现了错误 前端错误信息 后台处理以及报错信息 16:37:36,034 ERRO ...
- 【转】在Win10家庭版中启用组策略
源地址:https://www.baidu.com/link?url=tZrD7LVxQEKQUTWUum86LoxyaxWNLs5BeBE2K36TliRi8sjGraKc-iP3TEm6sc_KX ...
- centos虚拟机设置静态ip
1.虚拟机网络配置设置为桥接模式 2.设置配置文件: vi /etc/sysconfig/network-scripts/ifcfg-ens33 DEVICE=ens33 HWADDR=:0c::c3 ...
- 洛谷 P2330 [SCOI2005]繁忙的都市(最小生成树)
嗯... 题目链接:https://www.luogu.org/problemnew/show/P2330 这道题的问法也实在是太模板了吧: 1.改造的道路越少越好 2.能够把所有的交叉路口直接或间接 ...
- Qt 学习之路 2(65):访问网络(1)
Home / Qt 学习之路 2 / Qt 学习之路 2(65):访问网络(1) Qt 学习之路 2(65):访问网络(1) 豆子 2013年10月11日 Qt 学习之路 2 18条评论 现在 ...
- 吴裕雄 python 机器学习——密度聚类DBSCAN模型
import numpy as np import matplotlib.pyplot as plt from sklearn import cluster from sklearn.metrics ...
- apache的URL重写
apache的url重写 第一步:修改apache\conf目录下的的httpd.conf文件 1.加载apache的url重写模块 大概122行:LoadModule rewrite_module ...
- Python第一天学习成果
1.变成可执行程序,在开头需加#!/usr/bin/env python找解释器 2.Python不支持常量,但建议用全大写就表明是常量 3.Unicode:2字节 ASCII:1字节 UTF-8(可 ...
- 【算法笔记】B1031 查验身份证
1031 查验身份证 (15 分) 一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2 ...