4.19打卡

二、设计思路

1.首先判断指定日期年份是否为闰年

2.然后计算出指定日期到1990年1月1日有多少天

3.三天打鱼两天晒网,一个周期为5天,将算出的天数除以5。

4.根据上一步计算结果的余数判断是打鱼还是晒网

 (余数为1,2,3为打鱼,余数为4,5则为晒网)

三、程序流程图

四、代码实现

复制代码
#include<bits/stdc++.h>
using namespace std;
typedef struct date
{
    int year, month, day;
}DATE;
int countDay(DATE);
int runYear(int);
int main(void)
{
    DATE today;
    int totalDay, result;//输入指定日期 
    printf("请输入指定日期,包括年,月,日 如:1999 1 1\n ");
    scanf("%d %d %d", &today.year, &today.month, &today.day);
    totalDay=countDay(today);//计算天数 
    result=totalDay%5;//计算余数 
    if(result>0 && result<4)
    {
        printf("今天打鱼");
    }
    else
    {
        printf("今天晒网"); 
    }
    return 0;
}

//判断是否为闰年
int runYear(int year)
{
    if((year%4 == 0 && year%100 != 0) || (year%400==0))
    {
        return 1;
    }
    else 
    {
        return 0;
    }
 } 
 
 //计算指定日期到1990年1月1日的天数 
 int countDay(DATE currentDay)
 {
     int perMonth[13]={0,31,28,31,30,31,30,31,31,30,31,30};
     int totalDay=0,year,i;
     for(year=1990;year<currentDay.year;year++)
     {
         if(runYear(year))
         {
             totalDay=totalDay+366;
         }
         else 
         {
             totalDay=totalDay+365;
        }
             
     }
     if(runYear(currentDay.year))
     
         perMonth[2]+=1;
     
     for(i=0;i<currentDay.month;i++)
     
         totalDay+=perMonth[i];
     
     totalDay+=currentDay.day;
     return totalDay;
         
         
 }
复制代码

 

posted @   yblll  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示