发布网友 发布时间:2022-04-22 08:16
共5个回答
热心网友 时间:2023-09-26 15:53
先指出你错在哪儿:
不是说一定是每年都是365天的,所以if(day%5>0&&day%5<4) 为打鱼的日子,并不一定成立。
如果从一年的第一天开始打鱼,则第四,五天晒网,第六天又开始打鱼,一个循环为5天,一年正好365天可以被5整除,如果是闰年则多一天,不能被整除,会使最后一天变为打渔,而下一年则在能被5整除的数字减一之后才结束一次循环,这样下去,5个闰年之后会变回正常状态。
但是有一个问题:
1992 10 25 的确应该是打鱼的啊
1993 10 25 应是“sleep”的
==================================
下面是变更后的代码:
已经编译运行确认。
#include<stdio.h>
#include<conio.h>
#include <string.h>
#include <stdio.h>
int Run(int);
int yd(int,int,int);
int yyd(int);
int cr=0;
void main()
{
int y,m,d,day;
int i = 0,j=0;
printf("input \"year month day\":");
scanf("%d%d%d",&y,&m,&d);
printf("\n year : %d\n",y);
printf("\n month : %d\n",m);
printf("\n day : %d\n",d);
day=yyd(y)+yd(y,m,d);
cr = 0;
if ( y == 1990 )
{
cr = 0;
}
else
{
for(j=1990;j<y;j++)
{
if(Run(j))
cr++;
}
}
//if(day%5>0&&day%5<4)
//printf("do\n");
//else
//printf("sleep\n");
switch( cr%5 )
{
case 1:
if((day%5 == 1) ||(day%5 == 2)||(day%5 == 0))
printf("do\n");
else
printf("sleep\n");
break;
case 2:
if((day%5 == 1) ||(day%5 == 4)||(day%5 == 0))
printf("do\n");
else
printf("sleep\n");
break;
case 3:
if((day%5 == 3) ||(day%5 == 4)||(day%5 == 0))
printf("do\n");
else
printf("sleep\n");
break;
case 4:
if((day%5 == 2) ||(day%5 == 3)||(day%5 == 4))
printf("do\n");
else
printf("sleep\n");
break;
case 0:
if((day%5 == 1) ||(day%5 == 2)||(day%5 == 3))
printf("do\n");
else
printf("sleep\n");
break;
}
getch();
}
int Run(int y)
{
return ((y%4==0&&y%100!=0)||y%400==0)?1:0;
}
int yd(int y,int m,int d)
{
int i,a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
for(i=0;i<m-1;i++)
d+=a[i];
if(Run(y)&&m>2)
d++;
return d;
}
int yyd(int y)
{
int i,yyd;
for(i=1990;i<y;i++)
if(Run(y))
cr++;
return yyd=cr*366+(y-1990-cr)*365;
}
热心网友 时间:2023-09-26 15:54
注意:
3天(day%5=0,1,2)打鱼,2天(day%5=3,4)晒网。
而不是4天打鱼,1天晒网
#include <stdio.h>
int Run(int);
int yd(int,int,int);
int yyd(int);
void main()
{
int y,m,d,day;
printf("input \"year month day\":");
scanf("%d%d%d",&y,&m,&d);
day=yyd(y)+yd(y,m,d);
if(day%5>0&&day%5<3)/////////////////////4)
printf("do\n");
else
printf("sleep\n");
}
int Run(int y)
{
return ((y%4==0&&y%100!=0)||y%400==0)?1:0;
}
int yd(int y,int m,int d)
{
int i,a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
for(i=0;i<m-1;i++)
d+=a[i];
if(Run(y)&&m>2)
d++;
return d;
}
int yyd(int y)
{
int cr=0,i,yyd;
for(i=1990;i<y;i++)
if(Run(y))
cr++;
return yyd=cr*366+(y-1990-cr)*365;
}
热心网友 时间:2023-09-26 15:54
#include<stdio.h>
#include<assert.h>
int TotalDays(int year,int month,int day)
{
assert((year-1990)>=0);
assert(month>0 && month<13);
assert(day>0 && day<32);
int sum=0;//返回总的天数
for(int i=1990;i<year;i++)//判断中间的瑞年
{
if((i%4)==0 || ((i%100)==0 && (i%400!=0)))
sum+=366;
sum+=365;
}
if((year%4)==0 &&((year%100)!=0|| (year%400==0)))//如果year是瑞年
{
switch(month)
{
case 1:break;
case 2:sum+=31;break;
case 3:sum+=60;break;
case 4:sum+=91;break;
case 5:sum+=121;break;
case 6:sum+=152;break;
case 7:sum+=182;break;
case 8:sum+=213;break;
case 9:sum+=244;break;
case 10:sum+=274;break;
case 11:sum+=305;break;
case 12:sum+=335;break;
}
}
else
{
switch(month)
{
case 1:break;
case 2:sum+=31;break;
case 3:sum+=59;break;
case 4:sum+=90;break;
case 5:sum+=120;break;
case 6:sum+=151;break;
case 7:sum+=181;break;
case 8:sum+=212;break;
case 9:sum+=243;break;
case 10:sum+=273;break;
case 11:sum+=304;break;
case 12:sum+=334;break;
}
}
return sum+day;
}
void main()
{
int year,month,day;
scanf("%d%d%d",&year,&month,&day);
int totaldays=TotalDays(year,month,day);
switch(totaldays % 5)
{
case 0:
case 1:
case 2:printf("do\n");break;
case 3:
case 4:printf("sleep\n");break;
default:break;
}
}
热心网友 时间:2023-09-26 15:55
#include <stdio.h>
int yyr(int y,int m,int d);
int main()
{
int y,m,d,day;
printf("input \"year month day\":");
scanf("%d%d%d",&y,&m,&d);
day=yyr(y,m,d);
if(day)printf("do\n");
else
printf("sleep\n");
return (0);
}
int yyr(int y,int m,int d)
{
int i,k;
int mon[]={0,0,1,4,0,0,1,1,2,3,3,4,4};
i=y-1990;
for(k=0;i>0;i--,y--)
if((!(y%4))&&(m>2))k++;
d=(d+k+mon[m]);
d%=5;
d=d+1;
if(d<4)return(1);
else return(0);
}
呵呵,我的最短哦,刚在WinTC上编译试过,OK
还有,你男的女的?美女的话可以交个朋友
热心网友 时间:2023-09-26 15:55
#include <stdio.h>
int Run(int);
int yd(int,int,int);
int yyd(int);
void main()
{
int y,m,d,day;
printf("input \"year month day\":");
scanf("%d%d%d",&y,&m,&d);
day=yyd(y)+yd(y,m,d);
if(day%5>=0&&day%5<=3)/////////////////////4)
printf("do\n");
else
printf("sleep\n");
}
int Run(int y)
{
return ((y%4==0&&y%100!=0)||y%400==0)?1:0;
}
int yd(int y,int m,int d)
{
int i,a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
for(i=0;i<m-1;i++)
d+=a[i];
if(Run(y)&&m>2)
d++;
return d;
}
int yyd(int y)
{
int cr=0,i,yyd;
for(i=1990;i<y;i++)
if(Run(y))
cr++;
return yyd=cr*366+(y-1990-cr)*365;
}