HDU 1201(18岁生日天数)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring> 
using namespace std;
const int MAXN = 10000 + 10;
int months[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

/*
HDU 1201
关键: T组测试数据, 每一组测试数据输入之前都要保证前面用到的数据没有保留
*/

bool isPlanted(int year){
	return !( (year%4==0 && year%100!=0) || (year%400)==0 );
}

int main(){
	int T;
	scanf("%d", &T);
	for(int i=0; i<T; i++){
		int year, month, day;
		year = month = day = 0;
		scanf("%d-%d-%d", &year,&month,&day);
		
		if( (month==2) && (day==29) && !isPlanted(year) ){
			cout << -1 << endl;
			continue;
		}else if( !isPlanted(year) ){
			months[2] = 29;
		}else{
			months[2] = 28;
		}
		/
		int days=0, sum = 0;			// days->生日离该年1月1日有几天, sum->18年后的生日离该年1月1日有几天 
		for( int m=1; m<month; m++){
			days += months[m];
		}
		days += day;
		for( int y=year; y<year+18; y++){
			if( isPlanted(y) ){
				sum += 365;
			}else{
				sum += 366;
			}
		}
		if( isPlanted(year+18) ){
			months[2] = 28;
		}else {
			months[2] = 29;
		}
		for( int m=1; m<month; m++){
			sum += months[m];
		}
		sum += day;
		cout << (sum-days) << endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值