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 ...
随机推荐
- Persistent and Transient Data Structures in Clojure
此文已由作者张佃鹏授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 最近在项目中用到了Transient数据结构,使用该数据结构对程序执行效率会有一定的提高.刚刚接触Trans ...
- Socket 简易静态服务器 WPF MVVM模式(一)
整体代码下载 主要实现功能: Socket的简单应用 可修改IP和端口 显示来访信息 界面设计: 界面采用MVVM设计,很简陋. 前台的主要目的是 输入IP地址 输入端口 输入文件目录 开启监听和停止 ...
- 《C#多线程编程实战》2.4 SemaphoreSlim
这个简单多了. 理解也是很好理解. 比上一个mutex好理解多了. 这个SemaphoreSlim是干什么呢? 就是限制线程的来访问. 好比说一次只有两个,一次只有三个 这样的线程来访问资源. 有点 ...
- oracle为IN OUT变量或OUT变量赋值时提示“表达式''不能用作赋值目标”
是因为IN OUT变量和OUT变量是要输出的,不能赋给它常量值,这样它就不能再被赋值而输出了,所以是禁止赋常量值的,比如''也是常量值,也不可以赋给这两种类型的变量,如果不能把存储过程中的其他变量赋给 ...
- Selenium3+python异常后截图(screenshot)
前言 在执行用例过程中由于是无人值守的,用例运行报错的时候,我们希望能对当前屏幕截图,留下证据. 在写用例的时候,最后一步是断言,可以把截图的动作放在断言这里,那么如何在断言失败后截图呢? 一.截图方 ...
- 在DZ 中 showmessage 中可以再次执行 JS
showmessage ( '登录', '', array (), array ( 'showdialog' => 0, ...
- python创建shape
import shapefile import json import os #shapefile="polygon.shp"; #jsonfile="社区网格.json ...
- [Python]打印a..z的字符
import string print string.letters[0:26]
- 【转】idea project中导入其他文件夹下的模块,可能出现java.io.FileNotFoundException: XXX.xml
在一个project 中导入一个java 模块, 我要执行该模块的main函数 ,在main函数中有一个 FileReader(“generatorConfig.xml”) 而generatorCon ...
- windows cmd下创建虚拟环境virtualenv
一:虚拟环境virtualenv 如果在一台电脑上, 想开发多个不同的项目, 需要用到同一个包的不同版本, 如果使用上面的命令, 在同一个目录下安装或者更新, 新版本会覆盖以前的版本, 其它的项目就无 ...