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 ...
随机推荐
- rsync服务搭建--2018.5.8 [优化后最终版]
2018年5月8日 22:09:38 第一步配置基础环境(按照自己的规划配置并非每人的环境都一致) 第一台服务器(RSYNC服务器): rsync外网地址:10.0.0.41 rsync内网地址:1 ...
- HashMap数据结构的C++实现
Hash表在计算机的应用编程中是一种很常用的数据结构,很多算法的实现都离不开它.虽然C++11标准模板库中的有hashmap类型的实现,但在工程实践中,若项目本身使用的是较低版本的C++,或是出于性能 ...
- [Algorithm]图
一.图的算法 邻接矩阵表示的数据结构 1 #define INFINITY INT_MAX // 无穷大 2 #define MAX_VERTEX_NUM 20 // 限制顶点最大数值为20个 3 # ...
- javaee--学生成绩录入与显示--Struts2标签的使用
类Score.java:各课程的成绩及平均成绩 类Student.java:学生姓名.学号及Score类 类ScoreAction.java:将Student类存在一个List对象中, execute ...
- Linux解压工具
指令 yum install lrzsz
- 日期 Date()
1.Date 对象用于处理日期和时间.创建 Date 对象的语法:var myDate=new Date()Date 对象会自动把当前日期和时间保存为其初始值.2.参数形式有以下5种: new Dat ...
- kali linux之拒绝服务
Dos不是DOS(利用程序漏洞或一对一资源耗尽的denial of service拒绝服务) DDoS分布式拒绝服务(多对一的攻击汇聚资源能力,重点在于量大,属于资源耗尽型) 历史 以前:欠缺技术能力 ...
- SDUT OJ 数据结构实验之链表八:Farey序列
数据结构实验之链表八:Farey序列 Time Limit: 10 ms Memory Limit: 600 KiB Submit Statistic Discuss Problem Descript ...
- C#中实现https的双向认证
1. 把浏览器中的证书导出为cer文件. 2. 代码如下: using System; using System.Net; using System.IO; using System.Secur ...
- K3 Wise 常用表【转载】
在后台数据库ICClassType表中,字段FID<0的是老单,FID>0的是新单.--事务类型select * from ICClassType where FT ...