*6-2 CCF 2015-03-3 节日

23 篇文章 0 订阅

题目描述

在这里插入图片描述

源代码

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;

const int N = 1000;
int monthdays[2][13] = { {0,31,28,31,30,31,30,31,31,30,31,30,31},
	{0,31,29,31,30,31,30,31,31,30,31,30,31} };
int isleapyear(int year)
{
	return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 1 : 0;
}
int main()
{
	int a, b, c, y1, y2;
	int weekd, d, leap;
	cin >> a >> b >> c >> y1 >> y2;
	int basedays = 0;
	//计算从1850年到y1年的天数
	//for(int i=1850;i<y1;i++)
		//basedays+=365+isleapyear(i);
	basedays = (y1 - 1850) * 365 + (y1 - 1850) / 4 - (y1 - 1850) / 100 + (y1 - 1850) / 400;
	//计算年月日并且输出
	for (int i = y1; i <= y2; i++)
	{
		int base_weekday = 2;//每次计算新的年份时 都是以1850年1月1日为基数 :星期二
		leap = isleapyear(i);
		//计算i年a月1日是该年的第几天
		int days = 0;
		for (int j = 1; j < a; j++)
			days += monthdays[leap][j];
		//把1850年1月1日 到i年a月1日的总天数与7求余
		base_weekday += (basedays + days) % 7;
		if (base_weekday > 7)
			base_weekday %= 7;//i年a月1日是星期几
		int d = 1, num = 0;//d记录月份的天数 num 记录当月的第几个星期c
		while (1)
		{
			if (base_weekday == c)
			{
				num++;
			}
			if (num == b) break;
			base_weekday++;
			if (base_weekday > 7) base_weekday = 1;
			d++;
		}
		if (d > monthdays[leap][a])
			cout << "none" << endl;
		else
		{
			cout << i << "/";
			if (a < 10) cout << "0";
			cout << a << "/";
			if (d < 10) cout << "0";
			cout << d << endl;
		}
		basedays += 365 + leap;
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值