C语言-中国有句俗语叫 “ 三天打鱼两天晒网 ”。某人从 1990 年 1 月 1 日起开始 “三天打鱼两天晒网”,问这个人在以后的某一天中是 “打鱼” 还是 “晒网”。

题目如标题所示

//by GAIN_HZ
 
#include<stdio.h>
#include<string.h>

typedef struct date
{
	int year;
	int month;
	int day;

} date; //定义日期结构体

int leap_year(int year) //判断是否是闰年 
{
	if( (year%4==0 && year%100!=0) || year%400==0 )
	return 1;
	
	return 0; 
}

int count(date today)//计算天数
{
	int permonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};	
	
	int total_days=0,year=0,month=0;
	
	for( year=1990 ; year<today.year ; year++)//累计加到上一年 并且判断闰年 
	{
		if(leap_year(year))//判断闰年
		  total_days+=366;
		  else
		  total_days+=365;
	}
	
	if(leap_year(today.year))//判断今年是否是闰年如果是,二月加一到29 
	  permonth[2]++;
	
	
	for( month=1 ; month<today.month ;month++) //累计加到上一个月 
	{
		total_days+=permonth[month]; 
	}
	
	total_days+=today.day; //加这个月的天数
	
	return total_days;//返回1990 1 1到今天所经历的天数

}

int FishNet(int total_days)//判断打鱼还是晒网
{
	int result=total_days%5;

	if( result>=1 && result<=3 )
	  return 1;
	  
	  return 0;
}

int main()
{
	date today;
	
	int total_days;
	
	scanf("%d %d %d", &today.year, &today.month, &today.day);//输入形式1990 1 1
	
	total_days=count(today);//计算全部的天数,用于FishNet判断
	
	if(FishNet(total_days))
	  printf("打鱼");
	  else
	  printf("晒网"); 
		
	return 0;
} 

是根据这位大佬的思路写的,程序内容也大差不差-点击这句话可以进入链接


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值