HDU

细节很多,可以先算365*18再判断其他的情况再分别加一
#include <iostream>
#include<cstdio>
using namespace std;
bool ifrun(int n){
    if((n%4==0&&n%100!=0) ||n%400==0)
        return 1;
    return 0;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,y,r;
        scanf("%d-%d-%d",&n,&y,&r);
        int s=0;
        if(!ifrun(n+18)&&r==29&&y==2)
        {
            cout<<"-1"<<endl;
            continue;
        }
        s=18*365;
        for(int i=1;i<18;i++)
        {
            s+=ifrun(n+i);
        }
        if(y>2)
        {
            s+=ifrun(18+n);
        }
        else if(y<2||r!=29)
            s+=ifrun(n);
        cout<<s<<endl;
    }
    return 0;
}

posted @ 2018-04-23 00:27  MCQ  阅读(293)  评论(0编辑  收藏  举报