2015 编程之美 资格赛 第一题 hihocoder 区间闰年 2月29 数量 模拟题

 

 

#include <string.h>   ->memset()的头文件

http://hihocoder.com/contest/msbop2015qual/problem/1

 

#include <iostream>
#include <string>
#include <stdio.h>
#include <memory>
#include <string.h>
using namespace std;
string m[]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" , "December"};
class year2
{
public :
    int year;
    string mouth;
    int day;
    int i_mouth;
    int special;
    void tran_mouth()
    {
        for(int i=0;i<12;i++)
            if(mouth==m[i])
                i_mouth=i+1;
    };
    void cal()
    {
        special=year/4-year/100+year/400;
    };
    bool is_special()
    {
        if(year%400==0||(year%4==0&&year%100!=0))
        {
            return true;
        }
        return false;
    };
    bool before_include_special()
    {
        if(i_mouth<2||(i_mouth==2&&day<=29))
            return true;
        else 
            return false;
    };
    bool before_special()
    {
        if(i_mouth<2||(i_mouth==2&&day<29))
            return true;
        else 
            return false;
    };
};
int main()
{
    int T;
    int Case=0;
    cin>>T;
    
    while(T--)
    {
        char t;
        Case++;
        year2 start;
        year2 end;
        cin>>start.mouth;
        cin>>start.day;
        cin>>t;
        cin>>start.year;

        cin>>end.mouth;
        cin>> end.day;
        cin>> t;
        cin>> end.year;

        start.tran_mouth();
        start.cal();
        end.tran_mouth();
        end.cal();

        int ans= end.special- start.special;
        if(start.is_special()&&start.before_include_special())
        {
            ans+=1;
        }
        if(end.is_special()&&end.before_special())
        {
            ans-=1;
        }
        cout<<"Case #"<<Case<<": "<<ans<<endl;
    }

}

 

转载于:https://www.cnblogs.com/tjsudys/p/4435137.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值