HDU-6112 今夕何夕

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=6112

题目分析:

         365%7=1,过一个平常年星期数多一天,用sum计算隔了多少天,如果sum%7==0那么这年的同一天和所求天的星期一致。特别要主注意闰年和2月29日,如果是在2月29日之前,如果今年是闰年,sum+=2,如果是平常年sum+=1。如果是2月29日之后,那么考虑下一年是否是闰年,如果是闰年,则sum+=2,如果是平常年sum+=1。

#include<iostream>
#include<cstdio>
using namespace std;
bool leapYear(int year){
	return year%400==0||(year%4==0&&year%100!=0);
}
int main(void)
{
	int n;
	cin>>n;
	while(n--){
		int a,b,c,sum=0;
		scanf("%d-%d-%d",&a,&b,&c);
		int y = a;
	    do{
	    	if(b==1||(b==2&&c<29)){
	    		if(leapYear(y)){
	    			sum+=2;
				}
				else{
					sum+=1;
				}
			}
			else{
				if(leapYear(y+1)){
					sum+=2;
				}
				else{
					sum+=1;
				}
			}
			y++;
		}while(sum%7!=0 || ((b==2&&c==29)?!leapYear(y):0));
		cout<<y<<endl;
	}
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值