博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lightoj - 1414 February 29
阅读量:5926 次
发布时间:2019-06-19

本文共 2767 字,大约阅读时间需要 9 分钟。

Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

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

Source

Problem Setter: Md. Arifuzzaman Arif
Special Thanks: Jane Alam Jan
 
#include  #include 
#include
using namespace std;map
mp;char month[20][25]={
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; bool judge(int y){ if((y%4==0 && y%100 !=0) || y%400 ==0) return true; return false;}int main() { for(int i=0; i< 12; i++) mp[month[i]]= i+1; int t, Q=1; scanf("%d", &t); while(t--) { char a[25]; int m, y; scanf("%s%d,%d", a, &m, &y); int t1=0, t2 =0; int bb=mp[a]; if(judge(y)) { if(bb>2) y++; } y--; t1+=y/4-y/100+y/400; scanf("%s%d,%d", a, &m, &y); if(judge(y)) { if(mp[a]>2|| (mp[a]== 2 && m==29)) y++; } y--; t2= t2+y/4-y/100+y/400; printf("Case %d: %d\n", Q++, t2-t1); } return 0;}

 

转载于:https://www.cnblogs.com/soTired/p/5451026.html

你可能感兴趣的文章
怎样在 Linux 中限制网络带宽使用
查看>>
Oracle10g常见HINT的用法
查看>>
EMC VNXe3200 lun的在线扩容
查看>>
【两地三中心】两地三中心--灾备解决方案
查看>>
制作liveusb实现centos6.2全自动无人职守安装
查看>>
SQL GROUP BY 语句
查看>>
我的友情链接
查看>>
网络营销与电子商务
查看>>
powershell查看计算机最后登录时间
查看>>
IPSEC ×××实验二:ASA IPSEC ×××
查看>>
centos EMQTTD 集群安装配置与测试验证
查看>>
HC3i论坛医疗信息化资料30个
查看>>
lvs+keepalive 比较详细的安装配置文档
查看>>
什么是Gratuitous ARP
查看>>
Dynamic ARP Inspection(DAI)动态ARP检测
查看>>
业务表构建中一些特殊字符作为列名的构建示例
查看>>
oracle11gRAC环境使用RMAN备份方案
查看>>
JavaScript基础之程序流程的三大结构
查看>>
shell的详细介绍和编程(中)
查看>>
nginx+fastcgi+mono 环境搭建
查看>>