发布网友 发布时间:2022-04-25 04:02
共4个回答
热心网友 时间:2023-10-24 17:11
你好!
程序发上来,你看看吧,满意请采纳
热心网友 时间:2023-10-24 17:12
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
int main ( int argc, char **argv )
{
char iBgnYear[5];
char iBgnMon[3];
char iBgnDay[3];
char iEndYear[5];
char iEndMon[3];
char iEndDay[3];
char iBgnDate[9];
char iEndDate[9];
int iDays;
int tDay;
struct tm iBgnTm;
struct tm iEndTm;
memset( iBgnDate, 0x00, sizeof( iBgnDate ));
memset( iEndDate, 0x00, sizeof( iEndDate ));
fprintf( stdout, "假设捕鱼者从[20140101]开始3天捕鱼, 2天晒网\n" );
fprintf( stdout, "请输入您要查看捕鱼者在做甚的日期:" );
scanf( "%s", iEndDate );
memcpy( iBgnDate, "20140101", 8 );
memset( iBgnYear, 0x00, sizeof( iBgnYear ));
memset( iBgnMon, 0x00, sizeof( iBgnMon ));
memset( iBgnDay, 0x00, sizeof( iBgnDay ));
memset( iEndYear, 0x00, sizeof( iEndYear ));
memset( iEndMon, 0x00, sizeof( iEndMon ));
memset( iEndDay, 0x00, sizeof( iEndDay ));
memcpy( iBgnYear, "2014", 4 );
memcpy( iBgnMon, "01", 2 );
memcpy( iBgnDay, "01", 2 );
memcpy( iEndYear, &iEndDate[0], 4 );
memcpy( iEndMon, &iEndDate[4], 2 );
memcpy( iEndDay, &iEndDate[6], 2 );
memset( &iBgnTm, 0x00, sizeof( iBgnTm ));
memset( &iEndTm, 0x00, sizeof( iEndTm ));
iBgnTm.tm_year = atoi( iBgnYear ) - 1900;
iBgnTm.tm_mon = atoi( iBgnMon ) - 1;
iBgnTm.tm_mday = atoi( iBgnDay );
iEndTm.tm_year = atoi( iEndYear ) - 1900;
iEndTm.tm_mon = atoi( iEndMon ) - 1;
iEndTm.tm_mday = atoi( iEndDay );
iDays = (int)((mktime( &iEndTm ) - mktime( &iBgnTm )) / (24 * 60 * 60)) + 1;
tDay = iDays % 5;
if ( iDays <= 5 )
{
if ( iDays <= 3 ) fprintf( stdout, "捕鱼者在[%s]这天正在捕鱼\n", iEndDate );
else fprintf( stdout, "捕鱼者在[%s]这天正在晒网\n", iEndDate );
}
else
{
if ( tDay <= 3 ) fprintf( stdout, "捕鱼者在[%s]这天正在捕鱼\n", iEndDate );
else fprintf( stdout, "捕鱼者在[%s]这天正在晒网\n", iEndDate );
}
return 0;
}
代码及测试结果如上,纯手打!
热心网友 时间:2023-10-24 17:12
include<stdio.h>
int ruinian(int nian)
{
if((nian%4==0)&&(nian%400)!=0) { return 1; }
else
{ if(nian%400==0) return 1;
else return 0; }
}
main()
{
int nian ,yue ,ri,i;
int cnm=0,cnd;
printf("年月日!");
scanf("%d,%d,%d",&nian,&yue,&ri );
cnd=ruinian();
if(cnd )
{
for(i=1;i<nian+1;i++)
{
switch(i)
{
case 1: cnm+=31;break;
case 3: cnm+=31;break;
case 5: cnm+=31;break;
case 7: cnm+=31;break;
case 8: cnm+=31;break;
case 10: cnm+=31;break;
case 12: cnm+=31;break;
case 2:cnm+=29;break;
default: cnm+=30;
}
}
cnm+=ri;
else
{
switch(i)
{
case 1: cnm+=31;break;
case 3: cnm+=31;break;
case 5: cnm+=31;break;
case 7: cnm+=31;break;
case 8: cnm+=31;break;
case 10: cnm+=31;break;
case 12: cnm+=31;break;
case 2:cnm+=28;break;
default: cnm+=30;
}
cnm+=ri;
}
if((cnm%5)<3)
printf("打渔\n");
else
printf("晒网\n");
}
热心网友 时间:2023-10-24 17:13
first:某年1月1日
second:从键盘输入x年x月x日
int a = difftime(second,first);
int b = a%(5*800);
if(b>(3*800))
晒网
else
打鱼
没学过。没用过C语言。献丑了。