题意:http://www.lightoj.com/volume_showproblem.php?problem=1414

最原始的就是特判第一年以及最后一年  然后在for计算当中的个数  很容易超时

现在一个公式搞定,year/4-year/100+year/400即可  

但是判断的方法有一些本质的区别  先后肯定有所区别

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 10006
map<string,int>Q;
void dabiao()
{
 
    Q["January"]=1;Q["February"]=2;Q["March"]=3;
    Q["April"]=4;Q["May"]=5;Q["June"]=6;
    Q["July"]=7;Q["August"]=8;Q["September"]=9;
    Q["October"]=10;Q["November"]=11;Q["December"]=12;
}
int q(int x)
{
    if(x%4==0&&x%100||x%400==0)
        return 1;
    return 0;
}
int main()
{
    dabiao();
    int T,t=1;
    scanf("%d",&T);
    while(T--)
    {
        int e1,e2,f1,f2;
        char str1[12],str2[13];
        scanf("%s%d,%d",str1,&e1,&f1);
        scanf("%s%d,%d",str2,&e2,&f2);
        if(q(f1))
        {
            if(Q[str1]>2)
                f1++;
            else f1--;
        }
        if(q(f2))
        {
            if(Q[str2]>2||(Q[str2]==2&&e2==29))
                f2++;
            else f2--;
        }
        int sum1=f1/4+f1/400-f1/100;
        int sum2=f2/4+f2/400-f2/100;
        printf("Case %d: %d\n",t++,sum2-sum1);
    }
    return 0;
}

 

posted on 2017-10-17 15:36  云胡不喜。  阅读(116)  评论(0编辑  收藏  举报