HDU 1201-18岁生日(字符串)

address: http://acm.hdu.edu.cn/showproblem.php?pid=1201
Problem Description
Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达18岁生日所经过的总天数,让他好来比较一下。

Input
一个数T,后面T行每行有一个日期,格式是YYYY-MM-DD。如我的生日是1988-03-07。

Output
T行,每行一个数,表示此人从出生到18岁生日所经过的天数。如果这个人没有18岁生日,就输出-1。

Sample Input
1
1988-03-07

Sample Output
6574

code:

#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
bool f(int a)
{
    if (a%4==0&&a%100!=0||a%400==0)
        return true;
    else
        return false;
}
int main()
{
    int N;
    cin>>N;
    //getchar();
    while (N--)
    {
        int a,b,c;
        char x,y;
        int m;
        int i;
        int ans = 365*18;
        scanf ("%d%c%d%c%d",&a,&x,&b,&y,&c);
        //getchar();
            for (i=1;i<=17;i++)
            {
                m = a+i;
                if (f(m))
                    ans++;
            }
            if (f(a)&&b==2&&c==29)
            {
                cout<<-1<<endl;
                continue;
            }

            else if (f(a)&&f(a+18))
                ans++;
            else if (f(a)&&!f(a+18))
            {
                if (b<=2&&c<=28)
                    ans++;
            }
            else if (!f(a)&&f(a+18))
            {
                if (b>=3)
                    ans++;
            }
            cout<<ans<<endl;
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值