第九届蓝桥杯——星期一

【问题描述】

整个20世纪(1901年1月1日 至 2000年12月31日 之间),一共有多少个星期一?
(不要告诉我你不知道今天是星期几)

【答案提交】
注意:需要提交的只是一个整数,不要填写任何多余的内容或说明文字。


解题思路:

首先算出整个二十世纪有 36525 天,
然后打开电脑日历,发现 2000年12月31日 是星期天,
最后 36525 % 7 == 5217 余 6,所以一共有 5217 个星期一,且 1901年1月1日 是星期二。

题解:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

// 判断是不是闰年
bool judge(int year)
{
	if(year % 4 ==0 && year % 100 != 0 || year % 400 == 0) return true;
	return false;
}
int main()
{
	int ans = 0;
	for (int i = 1901; i <= 2000; i ++)
        if(judge(i)) ans += 366;
	    else ans += 365; 
	    
	cout << ans << endl;  
	cout << ans / 7 << endl;
	cout << ans % 7 << endl;  
	
	return 0;
}

答案:5217

卑微求赞↓↓↓

发布了63 篇原创文章 · 获赞 5 · 访问量 828

猜你喜欢

转载自blog.csdn.net/weixin_46239370/article/details/105467461