三天打鱼两天晒网

作者在 2009-12-21 15:20:54 发布以下内容

图片

#include "stdio.h"
#include "conio.h"

int fun2(int year,int month,int day)
{
 int daynow,daysum,month2,monthdays=0;
 
 if((year%4==0&&year%100!=0)||(year%400)==0)
  month2=29;
 else
  month2=28;
 switch(month)
 {
  case 1:
   daynow=31;
   daysum=0;
   break;
  case 2:
   daysum=31;
   break;
  case 3:
   daynow=31;
   daysum=month2+31;
   break;
  case 4:
   daynow=30;
   daysum=month2+62;
   break;
  case 5:
   daynow=31;
   daysum=month2+92;
   break;
  case 6:
   daynow=30;
   daysum=month2+123;
   break;
  case 7:
   daynow=31;
   daysum=month2+153;
   break;
  case 8:
   daynow=31;
   daysum=month2+184;
   break;
  case 9:
   daynow=30;
   daysum=month2+215;
   break;
  case 10:
   daynow=31;
   daysum=month2+245;
   break;
  case 11:
   daynow=30;
   daysum=month2+276;
   break;
  case 12:
   daysum=month2+306;
   break;
 }
 monthdays=daysum+day-1;
 //printf("monthdays=%d\n",monthdays);//用来测试
 return(monthdays);
}

long fun1(int year)
{
 long yeardays;

 yeardays=(year-1990)*365+(year-1990)/4-(year-1990)/100+(year-1990)/400;
 //printf("yeardays=%d\n",yeardays);
 return(yeardays);
}

int main(void)
{
 int year,month,day;
 long alldays;
 int mod;
 printf("****************************************************\n");
 printf("中国有句古话叫【三天打鱼两天晒网】\n");
 printf("某人从1990年1月1日开始【三天打鱼两天晒网】\n");
 printf("问这个人在输入的某一天里是【打鱼】还是【晒网】?\n");
 printf("****************************************************\n");
 while(1)
 {
  printf("请输入年-月-日:");
  scanf("%d-%d-%d",&year,&month,&day);
  if(year<1990||year>9999||month<=0||month>12||day<=0||day>31)
  {
   printf("无效的日期,退出程序。\n");
   return 0;
  }

  alldays=fun1(year)+fun2(year,month,day);
  //printf("alldays=%d\n",alldays);
  mod=alldays%5;
  //printf("mod=%d\n",mod);

  switch(mod)
  {
   case 1:
   case 2:
   case 3:
    printf("这天在打鱼!\n");
    getch();
    break;
   case 0:
   case 4:
    printf("这天在晒网!\n");
    getch();
    break;
  }
 }
 return 0;
}

默认分类 | 阅读 1563 次
文章评论,共2条
eumenides
2009-12-25 20:53
1
#include&lt;stdio.h&gt;<br />
<br />
 struct yea_mon_day{<br />
&nbsp;&nbsp;int year;<br />
&nbsp;&nbsp;int month;<br />
&nbsp;&nbsp;int day;<br />
 };<br />
 <br />
 void yea_mon(struct yea_mon_day date);<br />
 void jop(int days);<br />
 int year(int i);<br />
 int main(void)<br />
 {<br />
&nbsp;&nbsp;struct yea_mon_day date;<br />
&nbsp;&nbsp;int days,choice;<br />
&nbsp;&nbsp;do{<br />
&nbsp;&nbsp;printf(&quot;[1]输入天数\n[2]输入日期\n&quot;);<br />
&nbsp;&nbsp;printf(&quot;输入你的选择:&quot;);<br />
&nbsp;&nbsp;scanf(&quot;%d&quot;,&amp;choice);<br />
&nbsp;&nbsp;switch(choice){<br />
&nbsp;&nbsp;case 1:printf(&quot;输入你的天数:&quot;);<br />
&nbsp; &nbsp;scanf(&quot;%d&quot;,&amp;days);<br />
&nbsp; &nbsp;jop(days);break;<br />
&nbsp;&nbsp;case 2:printf(&quot;输入日期(1990年1月1日后:):&quot;);<br />
&nbsp; &nbsp;scanf(&quot;%d%d%d&quot;,&amp;date.year,&amp;date.month,&amp;date.day);<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp;yea_mon(date);break;<br />
&nbsp;&nbsp;case 0: break;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}while(choice!=0);<br />
&nbsp;&nbsp;printf(&quot;谢谢使用\n&quot;);<br />
&nbsp;&nbsp;return 0;<br />
 }<br />
&nbsp;&nbsp;void jop(int days)<br />
&nbsp;&nbsp;{<br />
&nbsp; &nbsp;if(days%5==1||days%5==2||days%5==3)<br />
&nbsp; &nbsp; printf(&quot;打渔\n&quot;);<br />
&nbsp; &nbsp;else printf(&quot;晒网\n&quot;);<br />
&nbsp; &nbsp;return;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;void yea_mon(struct yea_mon_day date)<br />
&nbsp;&nbsp;{<br />
&nbsp; &nbsp;int sum=0,leap,i;<br />
&nbsp; &nbsp;int a[2][13]={<br />
&nbsp; &nbsp; {0,31,28,31,30,31,30,31,31,30,31,30,31},<br />
&nbsp; &nbsp; {0,31,29,31,30,31,30,31,31,30,31,30,31},<br />
&nbsp; &nbsp;};<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;for(i=1990;i&lt;date.year;i++)<br />
&nbsp; &nbsp; sum=sum+year(i);<br />
leap=((date.year%4==0&amp;&amp;date.year%100!=0)||(date.year%400==0));<br />
for(i=1;i&lt;date.month;i++)<br />
sum=sum+a[leap]<i>;<br />
sum=sum+date.day;<br />
if(sum%5==1||sum%5==2||sum%5==3)<br />
printf(&quot;打渔\n&quot;);<br />
else printf(&quot;晒网\n&quot;);<br />
return;<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;int year(int i)<br />
&nbsp;&nbsp;{<br />
&nbsp; &nbsp;if((i%4==0&amp;&amp;i%100!=0)||(i%400==0))<br />
&nbsp; &nbsp; return 366;<br />
&nbsp; &nbsp;else return 365;<br />
&nbsp;&nbsp;}<br />
随便写了个,别介意
hnliji1107(作者)
2009-12-26 22:06
2
<div class="quote"><span class="q"><b>eumenides</b>: #include&lt;stdio.h&gt;<br />
<br />
 struct yea_mon_day{<br />
&nbsp;&nbsp;int year;<br />
&nbsp;&nbsp;int month;<br />
&nbsp;&nbsp;int day;<br />
 };<br />
 <br />
 void yea_mon(struct yea_mon_day date);<br />
 void jop(int days);<br /></span></div>不介意不介意,呵呵互相交流嘛
游客请输入验证码
文章分类