計算 [1年~結尾年份的2/29日期個數] – [1年~(初始年份-1)的2/29日期個數] = 即是兩個年份之間的2/29日期個數。
注意初始年份與結尾年份並不一定是所輸入之該年,必須注意當日是否會包含到該年之2/29日。
C++(0.012)
/*******************************************************/
/* UVa 12439 - February 29 */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2012/07/15 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int T;
string month;
int day, year;
int t1, t2;
while( scanf( "%d", &T ) != EOF ){
for( int i = 1 ; i <= T ; i++ ){
cin >> month;
scanf( "%d, %d", &day, &year );
if( (month[0] == 'J' && month[1] == 'a') || month[0] == 'F' ) year--;
t1 = year/4 - year/100 + year/400;
cin >> month;
scanf( "%d, %d", &day, &year );
if( (month[0] == 'J' && month[1] == 'a') || month[0] == 'F' ) year--;
if( month[0] == 'F' && day == 29 ) year++;
t2 = year/4 - year/100 + year/400;
printf( "Case %d: %d\n", i, t2-t1 );
}
}
return 0;
}