OJ:黑色星期五

OJ:黑色星期五

Description

众所周知,13号又是星期五成为“黑色星期五”,真的是一个不寻常的日子吗?13号是星期五比13号是星期一、13号是星期二、……、13号是星期日要少吗?我想知道这个问题的答案,所以想请聪明的你来写一个程序来计算在n年里每月13日落在星期一、星期二、……、星期日的次数。 
这个测试从1900年1月1日到1900+n-1年12月31日。n是一个正整数且不大于400。 
这里有一些你要知道的: 
    (1) 1900年1月1日是星期一。 
    (2) 4,6,11和9月有30天。其他月份除了2月有31天。闰年2月有29天,平	年2月有28天。 
    (3) 年份可以被4整除并且不能被100整除,或者能够被400整除,那么该年为闰年。例如,1992=4*498 所以 1992年是闰年,但是1990年不是闰年。1700,1800,1900和2100年是平年,而2000年是闰年。 

Input

有多个测试用例,每个测试用例的输入占一行,包含一个正整数n。 
n的表示为从1900之后的n年。 

Output

每个测试用例的输出占一行。 
该行有7个整数,整数之间用一个空格分隔,它们代表13日是星期六,星期日,星期一,……,星期五的次数。 		

Sample Input Copy

20

Sample Output Copy

36 33 34 33 35 35 34
#include<iostream>
using namespace std;

bool isLeap(int year);
int Count(int day, int year, int num[]);
void Contrast(int date, int num[]);

int main()
{
	
	int n;
	while (cin>>n) {
		int date = 1;
		int num[8] = { 0,0,0,0,0,0,0,0 };
		for (int year = 1900; year <= 1900 + n - 1; year++) {
			date = Count(date, year, num);
		}
		cout << num[6] << " ";
		cout << num[7] << " ";
		cout << num[1] << " ";
		cout << num[2] << " ";
		cout << num[3] << " ";
		cout << num[4] << " ";
		cout << num[5] << endl;
	}
	return 0;
}
bool isLeap(int year) {
	if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
		return true;
	else return false;
}
int Count(int date, int year, int num[]) {
	for (int mouth = 1; mouth <= 12; mouth++) {
		date = (date + 12) % 7;
		Contrast(date, num);
		if (mouth == 2) {
			if (isLeap(year))
				date = (date + 17) % 7;
			else
				date = (date + 16) % 7;
		}
		else if (mouth == 4 || mouth == 6 || mouth == 9 || mouth == 11) {
			date = (date + 18) % 7;
		}
		else {
			date = (date + 19) % 7;
		}
	}
	return date;
}
void Contrast(int date,int num[]) {
	switch (date)
	{
	case 1:num[1]++; break;
	case 2:num[2]++; break;
	case 3:num[3]++; break;
	case 4:num[4]++; break;
	case 5:num[5]++; break;
	case 6:num[6]++; break;
	case 0:num[7]++; break;
	default:break;
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值