hdu 1201

OJ

#include <iostream>
#include <cstdio>

using namespace std;

int ar[12]={31,28,31,30,31,30,31,31,30,31,30,31};
bool isleapyear(int year)
{
	if(year%4==0&&year%100!=0)return true;
	else if(year%400==0) return true;
	return false;
}

int calmonthday(int year,int month)
{
	int day = 0;
	day = ar[month-1];
	if(isleapyear(year)&&month==2) day += 1;
	return day;
}
int caldaydatebackfirstmonth(int year,int month,int day)
{
	int sum = 0;
	for(int i=1;i<month;i++)
		sum += calmonthday(year,i);
	sum += day;
	return sum;
}
int calbackmonth(int year,int month,int day)
{
	int sum = caldaydatebackfirstmonth(year,month,day);
	if(isleapyear(year)) return 366-sum;
	else return 365-sum;
}
int howdays(int year)
{
	if(isleapyear(year)) return 366;
	return 365;
}
int eigthyear(int year,int month,int day)
{
	int y = year+18;
	int sum = 0;
	sum = calbackmonth(year,month,day);
	for(int i=year+1;i<y;i++)
		sum += howdays(i);
	sum += caldaydatebackfirstmonth(y,month,day);
	return sum;
}
bool havebirthday(int year,int month,int day)
{
	int y = year+18;
	if(isleapyear(year) && month==2&&day == 29)
	{
		if(isleapyear(y)) return true;
		return false;
	}
	return true;
}
int main()
{
	int test;
	scanf("%d",&test);
	while(test--)
	{
		int year,month,day;
		scanf("%d-%d-%d",&year,&month,&day);
		if(!havebirthday(year,month,day)) 
			puts("-1");
		else
		printf("%d\n",eigthyear(year,month,day));
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值