三天打鱼两天晒网

#include <stdio.h>
typedef struct date
{
	int year, month, day;
}DATE;
int runYear(int year)
{
	if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
		return 1;		//闰年
	else return -1;		
}
int countday(int year ,int month,int day)
{
	int n = 0;
	int total = 0;
	int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; 
	for (int year_ = 1990; year_ < year; year_++) if (runYear(year_) == 1)n++;
	for (int i = 0; i < month - 1; i++)total += days[i];
	if (month >= 3 && runYear(year) == 1) total++;
	total += ((year - 1990) * 365 + n + day);
	return total % 5;
}
int main()
{
	DATE today;
	int totalday;
	printf("please input year month day:");
	scanf_s("%d %d %d", &today.year, &today.month, &today.day);
	totalday = countday(today.year, today.month, today.day);
	if (totalday == 0 || totalday == 4)
		printf("晒网");
	else printf("打鱼");
	return 0;
}

posted @ 2023-04-14 21:26  258333  阅读(6)  评论(0编辑  收藏  举报