February 29 (analog)

Source: Internet
Author: User

D-d Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%LLD &%llusubmit Status Practice Lightoj 1414

Description

It is, and it's a leap year. So there was a "February" in the year, which was called Leap Day. Interesting thing is the infant who'll born in this February, would get his/her birthday again in, which is Anoth ER leap year. So February is exists in leap years. Does leap year comes in every 4 years? Years that is divisible by 4 is leap years, but years that is divisible by is not leap years, unless they is divi Sible by + which case they is leap years.

In this problem, you'll be given and 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 would have a lines. First line represents the first date and second line represents the second date. Note that, the second date would not represent a date which arrives earlier than the first date. The dates'll is in this format- "Month day, year", see sample input for exact format. You is guaranteed that dates would be valid and the year would be in between 2 * 103 to 2 * 109. For your convenience, the month list and the number of days per months is given below. You can assume this all the given dates would be a valid date.

Output

For each case, print the case number and the number of leap days in between, 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

Puzzle: Give two dates, find the number of February 29 between, WA 9 times, fortunately ...

The second date would not represent a date which arrives earlier than the first date represents the second day larger than the number one;

Code:

1#include <cstdio>2#include <Set>3#include <queue>4#include <cstring>5#include <algorithm>6#include <map>7#include <string>8 using namespacestd;9 BOOLjsintYintRintYyintRR) {Ten     if(Y < yy)return true; One     if(Y > yy)return false; A     if(R <= RR)return true; -     return false; - } the BOOLRninty) { -     if(Y% -==0|| (Y%4==0&& y% -!=0)) -         return true; -     return false; + } -map<string,int>MP; + voidinit () { Amp["January"] =1; atmp["February"] =2; -mp["March"] =3; -mp["April"] =4; -mp[" May"] =5; -mp["June"] =6; -mp["July"] =7; inmp["August"] =8; -mp["September"] =9; tomp["October"] =Ten; +mp["November"] = One; -mp["December"] = A; the } * voidWorkint&y1,int&y2,int&AMP;M1,int&AMP;M2,int&AMP;D1,int&D2) { $     if(Y1 >y2) {Panax Notoginseng swap (y1,y2); - swap (M1,M2); the swap (D1,D2); +         return; A     } the     if(Y1 <y1) { +         return; -     } $     if(M1 >m2) { $ swap (y1,y2); - swap (M1,M2); - swap (D1,D2); the         return; -     }Wuyi     if(M1 <m2) { the         return; -     } Wu     if(D1 >D2) { - swap (y1,y2); About swap (M1,M2); $ swap (D1,D2); -         return; -     } - } A intFindinty) { +     intT, T1, T2; thet = (Y- -) /4+1; -T1 = (Y- -) / -+1; $T2 = (Y- -) / -+1; the     return(T-t1 +T2); the } the intMain () { the     intN, Kase =0; -     Chars1[ the], s2[ the]; in     intY1, d1, Y2, D2, M1, M2; thescanf"%d", &N); the init (); About      while(n--){ thescanf"%s%d,%d", S1, &AMP;D1, &y1); thescanf"%s%d,%d", S2, &AMP;D2, &y2); the         if(Mp.count (S1)) { +M1 =MP[S1]; -         } the         Else  while(1);Bayi         if(Mp.count (S2)) { theM2 =MP[S2]; the         } -         Else  while(1); -     //Work (Y1,Y2,M1,M2,D1,D2); the         if(Y1 = =y2) { the             if(RN (y1) && JS (m1,d1,2, in) && JS (2, in, M2, D2)) { theprintf"Case %d:%d\n", ++kase,1); the                 Continue; -             } theprintf"Case %d:%d\n", ++kase,0); the             Continue; the         }94         intt = Find (y2-1) -find (y1); the         if(RN (y1) && JS (m1,d1,2, in)) t++; the         if(Rn (y2) && JS (2, in, M2, D2)) t++; theprintf"Case %d:%d\n", ++Kase, T);98     } About     return 0; -}

February 29 (analog)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.