三天打鱼两天晒网(C++)

该程序接收一个日期输入,计算从2010年到输入年份之间的总天数,并根据日期判断输出是‘晒网’还是‘打鱼’。涉及到闰年计算和日期处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include <cstring>
using namespace std;
int main()
20101214
{
	int year1[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //
	int year2[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //
	int date;
	int year, mouth, day;
	cin >> date;
	year = date / 10000;
	st
	mouth = date % 10000 / 100;
	day = date % 100;
	int soc = 2010;
	int i = 0;
	int sum = 0;
	for (i = 0; soc < year; i++)
	{
		if (soc % 4 == 0 && soc % 100 != 0 || i % 400 == 0)
			sum += 366;
		else
			sum += 365;
		soc++;
	}
	if (soc % 4 == 0 && soc % 100 != 0 || i % 400 == 0)
	{
		for (int j = 0; j < mouth - 1; j++)
		{
			sum += year2[j];
		}
	}
	else
	{
		for (int j = 0; j < mouth - 1; j++)
		{
			sum += year1[j];
		}
	}
	sum = sum + day; //
	if (sum % 5 == 4||sum % 5 ==0)
		cout << "晒网";
	else
		cout << "打鱼";
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值