#19404: 求救:TLE


089487 (089487)

學校 : 國立臺灣師範大學附屬高級中學
編號 : 82069
來源 : [140.112.150.137]
最後登入時間 :
2024-10-03 16:28:37
a468. 12439 - February 29 -- UVa12439 | From: [223.136.150.251] | 發表日期 : 2019-09-29 11:20

#include<iostream>
//#include<string.h>
//#include<stdbool.h>
using namespace std;
int main()
{
string c,s;
string month[12]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November","December"};
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
int d,y,d2,y2,m=-1,m2=-1;
char ch;
cin>>c;
scanf("%d, %d",&d,&y);
cin>>s;
scanf("%d, %d",&d2,&y2);
for(int j=0;j<12;j++)
{
if(month[j]==c)m=j+1;
if(month[j]==s)m2=j+1;
if(m!=-1&&m2!=-1) break;
}
y+=(m>2);
y2-=(m2>2);
if(y>y2) y2=y;
int num=0;
if(y%4!=0) y=(y/4+1)*(4);
if(y>y2) {printf("0\n");continue;
}
for(int j=y;j<=y2;j+=4)
{
if(j%4==0)
{
if(j%100!=0||j%400==0)
num++;
}
}
printf("Case %d: %d\n",i,num);
}
return 0;
}

 
ZeroJudge Forum