CF 304B——Calendar——————【年月日计算】
2015-05-30 16:23
731 查看
B - Calendar
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 304B
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
Output
Input
Output
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 304B
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",¥,&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 */
相关文章推荐
- 教你搞定Android自定义View
- 黑马程序员--面向对象知识点总结(一)
- 设备节点的自动创建
- msp430学习笔记-实现开方log等计算及FFT算法(待续)
- 引入css外部样式表
- php环境搭建 wnmp
- 使ScrollView的初始位置置顶
- 【小萝莉说Crash】第二期:Unrecognized selector xxx 之 ForwardInvocation
- reason:'CALayer position contains NaN: [160 nan]'
- 多文档
- JS封装简单后代选择器
- Java编程思想之-反证法
- poj 3061 尺取法
- Leetcode: House Robber II
- Android实战简易教程-第四枪(ScrollView和HorizontalScrollView动态添加控件并提供事件监听)
- EMWIN中文字库添加方法
- DM3730 x-loader 分析 五
- Android自定义Layout
- 转载一段关于当今剩女现象的经典好文
- Android开发-将自定义View布局到Layout中并调用