2015编程之美资格赛-2月29日

来源:互联网 发布:舞蹈教学软件 编辑:程序博客网 时间:2024/05/01 12:11

资格赛,水水哒题目,因为参加蓝桥杯才开始做这一类日期的题目。

每次都要判断闰年!!!选择一种最简单的写法吧~

2月29日,好神奇~不过最关键的地方就是判断起始年和结束年是不是闰年,能不能含有2月29日~~~

水水的我哒水水的代码~~

#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <cstdlib>#include <climits>#include <sstream>#include <fstream>#include <cstdio>#include <string>#include <vector>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>using namespace std;const int INF = 0x7fffffff;typedef long long int LL;const int maxn = 100000 + 100;const int maxm = 100 + 10;#define max(a,b) (a)>(b)?(a):(b)#define min(a,b) (a)<(b)?(a):(b)#define MOD 100007int judge(int y){    if(y%4==0)    {        if(y%100==0)        {            if(y%400==0) return 1;            else return 0;        }        else return 1;    }    else return 0;}int trans(char m[]){    if(strcmp(m,"January")==0)       return 1;    else if(strcmp(m,"February")==0) return 2;    else if(strcmp(m,"March")==0)    return 3;    else if(strcmp(m,"April")==0)    return 4;    else if(strcmp(m,"May")==0)      return 5;    else if(strcmp(m,"June")==0)     return 6;    else if(strcmp(m,"July")==0)     return 7;    else if(strcmp(m,"August")==0)   return 8;    else if(strcmp(m,"September")==0)return 9;    else if(strcmp(m,"October")==0)  return 10;    else if(strcmp(m,"November")==0) return 11;    else if(strcmp(m,"December")==0) return 12;}int before(int m,int d,int y){    int yy=judge(y);    if(yy=1 && m<=2) return 1;    else return 0;}int after(int m,int d,int y){    int yy=judge(y);    if(yy==1 && ((m==2 && d==29) || m>2)) return 1;    else return 0;}int main(){    int T;    scanf("%d",&T);    for(int cases=1; cases<=T; cases++)    {        int ans=0;        char m1[maxm],m2[maxm];        int d1,d2;        int y1,y2;        scanf("%s %d, %d",m1,&d1,&y1);        scanf("%s %d, %d",m2,&d2,&y2);        int mo1=trans(m1),mo2=trans(m2);        if(y1==y2)        {            int f1=before(mo1,d1,y1);            int f2=after(mo2,d2,y1);            int n1=judge(y1);            if(n1) if(f1 && f2) ans++;        }        else        {            int f1=before(mo1,d1,y1);            int f2=after(mo2,d2,y2);            int n1=judge(y1);            int n2=judge(y2);            if(n1 && f1) ans++;            if(n2 && f2) ans++;        }        if(y2-y1>1)            for(int y=y1+1; y<y2; y++)            {                int yy=judge(y);                if(yy) ans++;            }        printf("Case #%d: %d\n",cases,ans);    }    return 0;}


0 0
原创粉丝点击