HDU 1201 18岁生日

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1201

 

水题...................

 

#include 
bool isleap(int y)			//判断闰年
{
	if((y%4==0&&y%100!=0)||y%400==0)
		return true;
	return false;
}
int main()
{
	int t;
	int i;
	int ans;
	int year,month,day;
	scanf("%d",&t);
	while(t--)
	{
		ans=0;
		scanf("%d-%d-%d",&year,&month,&day);
		for(i=year+1;i<=year+17;i++)
		{
			if(isleap(i))
				ans+=366;
			else
				ans+=365;
		}
		if(isleap(year)&&isleap(year+18))
			ans+=366;
		if((!isleap(year))&&isleap(year+18))
		{
			if(month<=2)
				ans+=365;
			else
				ans+=366;
		}
		if(isleap(year)&& (!isleap(year+18)) )
		{
			if (month>2)
				ans+=365;
			if (month<=2)
				ans+=366;
			if (month==2&&day==29)
				ans= -1;
			

		}
		if( (!isleap(year)) && (!isleap(year+18)) )
			ans+=365;

		printf("%d\n",ans);
	}
	return 0;
}


 

 

 

你可能感兴趣的:(HDU 1201 18岁生日)