light oj
来源:互联网 发布:python接口测试 编辑:程序博客网 时间:2024/05/01 17:45
Submit Status
Description
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
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
Sample Output
Case 1: 1
Case 2: 0
Case 3: 1
Case 4: 3
算闰年的方法在过程中判断避免了逐个讨论的特殊情况,十分巧妙
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cctype>#include <cmath>using namespace std;int judge(int k);char s[20];int main(){ int t, d, y, ncase=1; scanf("%d", &t); while(t--) { scanf(" %s %d,%d",s, &d, &y); int n=y/4-y/100+y/400; if(judge(y)) { if((s[0]=='J'&&s[1]=='a')||(s[0]=='F'&&s[1]=='e')) { n--; } } scanf(" %s %d,%d",s, &d, &y); int m=y/4-y/100+y/400; if(judge(y)) { if((s[0]=='J'&&s[1]=='a')||((s[0]=='F'&&s[1]=='e')&&d<29)) { m--; } } printf("Case %d: %d\n",ncase++,m-n); } return 0;}int judge(int k){ if((k%400==0)||(k%100!=0&&k%4==0)) { return 1; } else { return 0; }}
- light oj
- light oj
- Light OJ
- Light OJ
- Light OJ 1000
- Light OJ 1001
- Light OJ 1008
- Light OJ 1022
- Light OJ 1015
- Light OJ 1042
- light oj 1128
- Light OJ 1055 BFS
- Light OJ Beginners Problems
- Light OJ Basic Geometry
- Light OJ Basic Math
- light oj 1124
- Light OJ 1012
- Light OJ 1224
- PHP语言建立数据库和数据表(乱码的解决)
- C++学习笔记 将数据以特定的格式转换成字符串形式打印
- HDU 1728 逃离迷宫
- Android中pull解析xml文件
- HDU 5692 区间最大值+DFS序
- light oj
- CodeForces 699B One Bomb
- Java面经总结
- Jconsole
- python中ascii码和字符的转换
- FASText(下):FASText
- 基于链表的容器类bag实现
- NOIP2016#模拟考试 Day.2# T1 改错
- Spring MVC + mybatis实现的注册登录