hdu 1201 18岁生日

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
 
Author
Gardon
 
Source
 
起始需要特殊判断。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX 101
using namespace std;
int t,h,m,d;
bool isleap(int k) {
    if(k % 4 == 0 && k % 100 || k % 400 == 0) return true;
    return false;
}
int main() {
    scanf("%d",&t);
    while(t --) {
        int ans = 0;
        scanf("%d-%d-%d",&h,&m,&d);
        if(m == 2 && d == 29) printf("-1
");
        else {
            for(int i = 1;i <= 18;i ++) {
                if(isleap(h + i) && !(i == 18 && m < 3)) {
                    ans += 366;
                }
                else ans += 365;
            }
            if(isleap(h) && m < 3) ans ++;
            printf("%d
",ans);
        }
    }
}
原文地址:https://www.cnblogs.com/8023spz/p/9853762.html