/*从1990.1.1开始三天打渔两天晒网问 以后的某一天 是打渔还是晒网?
函数 输入: 某一天日期
输出: 是打渔还是晒网
返回: 无*/
问题如上所述:直接上代码。
#include<stdio.h>
typedef struct time
{
int year;
int month;
int day;
} date;
void judgefish(date today)
{
int i,totalday,flag,j;
int days_year=0,days_day=0;//days_year为到指定日期的前一年年底的天数。
//days_day为指定年开始到指定月份日期
int tab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}};
for(i=1990;i<=today.year-1;i++)
{
if((i%4==0&&i%100!=0 )|| (i%400==0))
days_year+=366;
else
days_year=days_year+365;
}
flag=(today.year%4==0 && today.year%100!=0 )|| (today.year%400==0);
//flag=1 表示当前为闰年,二月就是28,否则二月为29.
for(j=1;j<today.month;j++)
{
days_day=days_day+tab[flag][j];
}
totalday=days_year+days_day+today.day;//总共的天数
printf("这是第%d天\n",totalday);
if((totalday%5>0 ) && (totalday%5<4))
printf("这天在打渔\n");
else printf("这天在晒网\n");
}
void main()
{
date today;
while(1)
{
printf("请输入要查询的日期(格式为:xx-xx-xx 如1990-3-6):\n");
scanf("%d-%d-%d",&today.year,&today.month,&today.day);
judgefish(today);
}
}