某人从1990年1月1日起开始三天打鱼两天晒网问这个人在以后的某一天中是打鱼还是晒网\\程序如何改?

mirroatl207 2014-01-27 08:22:27


//中国有句俗语叫三天打鱼两天晒网。
//某人从1990年1月1日起开始三天打鱼两天晒网
//问这个人在以后的某一天中是打鱼还是晒网。
int days(struct date day);

struct date{
int year;
int month;
int day;
};

int _tmain(int argc, _TCHAR* argv[])
{
struct date today,term;
int yearday,year,day;
printf("Enter year/month/day:");
scanf("%d%d%d",&today.year,&today.month,&today.day);
term.month = 12;
for(yearday = 0 , year = 1990 ; year < today.year;year++)
{
term.year = year;
yearday += days(term);
}
yearday += days(today);
day = yearday%5;
if(day > 0 && day < 4)
printf("he was fishing at that day.\n");
else
printf("he was sleeping at that day.\n");
return 0;
}

int days(struct date day)
{
static int day_tab[2][13] = {
{0,31,28,31,20,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
int i,lp;
lp = day.year % 4 == 0 && day.year%100 != 0 || day.year % 400 == 0;
for(i = 1 ; i < day.month ; i++)
day.day += day_tab[lp][i];
return day.day;
}
...全文
794 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-01-28
  • 打赏
  • 举报
回复
仅供参考
#include <afxdisp.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, TCHAR* argv[]) {
    COleDateTime t;
    COleDateTimeSpan ts;
    CString s,fmt;
    int nYear;
    int nMonth;
    int nDay;
    int nHour;
    int nMin;
    int nSec;
    int lDays;
    int nHours;
    int nMins;
    int nSecs;
    int i,N;
    // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
        printf("Fatal Error: MFC initialization failed\n");
        return 1;
    }
    if (argc<13) {
        printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL|YYYY|YY}\n",argv[0]);
        return 2;
    }
    if (stricmp(argv[12],"SQL")==0) fmt="%Y-%m-%d %H:%M:%S";
    else if (stricmp(argv[12],"YYYY")==0) fmt="%Y%m%d %H%M%S";
    else if (stricmp(argv[12],"YY")==0) fmt="%y%m%d %H%M%S";
    else {
        printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL|YYYY|YY}\n",argv[0]);
        return 3;
    }
    nYear =atoi(argv[ 1]);
    nMonth=atoi(argv[ 2]);
    nDay  =atoi(argv[ 3]);
    nHour =atoi(argv[ 4]);
    nMin  =atoi(argv[ 5]);
    nSec  =atoi(argv[ 6]);
    lDays =atoi(argv[ 7]);
    nHours=atoi(argv[ 8]);
    nMins =atoi(argv[ 9]);
    nSecs =atoi(argv[10]);
    N     =atoi(argv[11]);
    if (N<=0) {
        printf("Usage:%s sYYYY sMM sDD shh smm sss pDD phh pmm pss n {SQL|YYYY|YY}\n",argv[0]);
        return 4;
    }
    t=COleDateTime( nYear, nMonth, nDay, nHour, nMin, nSec);
    ts=COleDateTimeSpan( lDays, nHours, nMins, nSecs );
    for (i=1;i<=N;i++) {
        s=t.Format(fmt);
        printf("%08d %s\n",i,s);
        t=t+ts;
    }
    return 0;
}
hui211314ddhui 2014-01-28
  • 打赏
  • 举报
回复
《程序员实用算法》--"时间与日期"章节
logiciel 2014-01-28
  • 打赏
  • 举报
回复
在以下这行: term.month = 12; 的前面或后面要增加: term.day = 1; 如果要按提示格式(year/month/day)输入,以下这行: scanf("%d%d%d",&today.year,&today.month,&today.day); 要改为: scanf("%d/%d/%d",&today.year,&today.month,&today.day);
mujiok2003 2014-01-27
  • 打赏
  • 举报
回复
每5天一个周期,就跟一周7天是一回事.
diff(base, then) % 5

64,683

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧