【日期】黑色星期五

在西方,星期五和数字13都代表着坏运气,两个不幸的个体最后结合成超级不幸的一天。所以,不管哪个月的十三日又恰逢星期五就叫"黑色星期五”。

输入:

    年份

输出:

    判断该年是否包含黑色星期五,如包含,给出具体日期

关键是如何判断每个月的13号是不是星期五

#include <stdio.h>
int Month[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
int leap_year(int year)
{
	int count = 0;
	int i = 0;
	for (i = 1900; i < year; i++)
	{
		if ((i % 400 == 0 )||( (i % 4) == 0 && (i % 100) != 0))
		{
			count++;
		}
	}
	return count;
}//算出闰年的个数
void black_friday(int year, int day)
{
	int flag = 0;//通过控制flag来控制闰年时候的2月天数
	int count = 0;
	int fitmonth[12]={0};
	int i = 0;
	if (year % 400 == 0 || (year % 4 == 0 && year % 10 != 0))
	{
		flag = 1;//闰年就要二月份+1天
	}
	int month = 1;
	int day1 = 13;
	int realday = 0;
	for (month = 1; month <= 12; month++)
	{
		int all_day = 0;
		for (int j = 0; j < month; j++)//通过循环来计算每个月到一月有多少天
		{
			all_day = Month[j] + all_day;
		}
		if (month > 2)//如果是大于2月,就要考虑闰月的事情了
		{
			all_day = all_day + flag;//不是闰月,flag=0;如果是闰月,flag=1
		}
		realday = all_day + day+day1;//得到真正的天数
		if (realday % 7 == 5)
		{
			count++;
			fitmonth[i] = month;//将满足条件的月份存储起来
			i++;
		}
	}
	if (count>1)//如果有2个月即以上,就是they are
	{
		printf("There are %d Black Fridays in year %d.\n", count,year);
		printf("They are:\n");
		for (int j = 0; j < i; j++)
		{
			printf("%d/%d/13\n",year, fitmonth[j]);
		}
	}
	else if (count == 1)//如果是一个月,就是It is
	{
		printf("There is 1 Black Friday in year %d.\n", year);
		printf("It is:\n");
		for (int j = 0; j < i; j++)
		{
			printf("%d/%d/13\n", year, fitmonth[j]);
		}
	}
}
int main()
{
	int year = 0;
	scanf("%d", &year);
	int month = 0;
	int day = 0;
	int leapyear = leap_year(year);//计算出从1900年到year前的闰年个数
	day = 365 * (year - 1900) + leapyear;//算出天数,方便后面计算星期
	black_friday(year, day);
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值