【Lightoj 1414 - February 29 】
来源:互联网 发布:adidas跑鞋系列 知乎 编辑:程序博客网 时间:2024/05/18 01:53
1414 - February 29
PDF (English) Statistics Forum
Time Limit: 1 second(s) Memory Limit: 32 MB
It is 2012, and it’s a leap year. So there is a “February 29” in this year, which is called leap day. Interesting thing is the infant who will born in this February 29, will get his/her birthday again in 2016, which is another leap year. So February 29 only exists in leap years. Does leap year comes in every 4 years? Years that are divisible by 4 are leap years, but years that are divisible by 100 are not leap years, unless they are divisible by 400 in which case they are leap years.
In this problem, you will be given two different date. You have to find the number of leap days in between them.
Input
Input starts with an integer T (≤ 550), denoting the number of test cases.
Each of the test cases will have two lines. First line represents the first date and second line represents the second date. Note that, the second date will not represent a date which arrives earlier than the first date. The dates will be in this format - “month day, year”, See sample input for exact format. You are guaranteed that dates will be valid and the year will be in between 2 * 103 to 2 * 109. For your convenience, the month list and the number of days per months are given below. You can assume that all the given dates will be a valid date.
Output
For each case, print the case number and the number of leap days in between two given dates (inclusive).
Sample Input
Output for Sample Input
4
January 12, 2012
March 19, 2012
August 12, 2899
August 12, 2901
August 12, 2000
August 12, 2005
February 29, 2004
February 29, 2012
Case 1: 1
Case 2: 0
Case 3: 1
Case 4: 3
Note
The names of the months are {“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November” and “December”}. And the numbers of days for the months are {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 and 31} respectively in a non-leap year. In a leap year, number of days for February is 29 days; others are same as shown in previous line.
不多说,代码一看就懂~~
AC代码 :
#include<bits/stdc++.h>typedef long long LL;char st[20];int main(){ int T,nl = 0,a; LL b,ans1,ans2; scanf("%d",&T); while(T--){ scanf("%s %d, %lld",st,&a,&b); if((b % 4 == 0 && b % 100 != 0) || b % 400 == 0) if(strcmp(st,"January") != 0 && strcmp(st,"February") != 0) b++; ans1 = (--b / 4 - b / 100 + b / 400); //b 减一是为了特判 b 为闰年的情况 scanf("%s %d, %lld",st,&a,&b); if((b % 4 == 0 && b % 100 != 0) || b % 400 == 0){ if(strcmp(st,"January") != 0 && strcmp(st,"February") != 0) b++; else if(strcmp(st,"February") == 0 && a == 29) b++; } ans2 = (--b / 4 - b / 100 + b / 400); printf("Case %d: %lld\n",++nl,ans2 - ans1); } return 0;}
- Lightoj 1414 - February 29
- lightoj 1414 February 29
- 【Lightoj 1414 - February 29 】
- lightoj 1414 - February 29
- LightOj 1414 1414 - February 29
- LIGHTOJ 1414 - February 29【Leap】
- 【LightOJ】1414 - February 29(容斥原理)
- lightoj-1414-February 29【容斥原理&&细节】
- Lightoj 1414 - February 29 (闰年统计,容斥定理)
- LightOJ - 1414 February 29 (日期模拟)有多少个2月29
- LightOJ-1414-February 29--总共多少个闰日?--两种解法
- Lingt oj 1414 - February 29
- light oj 1414 - February 29
- Light OJ-----1414---February 29
- Light 1414-February 29【容斥定理】
- UVa 12439 - February 29
- lightpoj-【February 29】
- Light oj 1414 - February 29【容斥原理】
- 深度递归遍历文件夹中所有文件
- 苏嵌3 16.11.1
- 慕课网-十天精通CSS3-CSS3中的变形与动画(上)
- 守护进程
- ext4 学习笔记(三) Ext.window.Window(白鹤翔第一季)
- 【Lightoj 1414 - February 29 】
- UVA - 10870 Recurrences (矩阵快速幂)
- POJ-3281 Dining(最大流)
- dnotify监控文件行为
- HDU-1598-find the most comfortable road
- mac关于.bash_profile环境变量配置的问题
- 简单的停车场程序
- 关于进程虚拟地址为什么是4G的讨论
- 作用域(基础篇)