导航:网站首页 >
C语言中国有句俗语叫做“三天打鱼两天晒网”求高手!
时间:2019-7-29
C语言中国有句俗语叫做“三天打鱼两天晒网”求高手!
中国有句俗语叫做“三天打鱼两天晒网”,这句话用在Tomcat身上正好.原来Tom从2000年1月1日搬到海边后每打三天鱼就要晒两天网.如今以前的邻居老鼠Jerry来看望Tom.请问Jerry会看到Tom在打鱼还是在晒网?
输入要求:
输入数据有多组,每组数据占一行,为Jerry看望Tom的日期,格式为yyyy-mm-dd.输入为“0”时结束,该数据不处理.
输出要求:
如果Tom在给定的日期打鱼,则输出yyyy-mm-dd:he was fishing at that day.;如果Tom在给定的日期晒网,则输出yyyy-mm-dd:he was sleeping at that day..如果对于给定的日期不存在或者早于2000年1月1日,则输出yyyy-mm-dd:Rrror!.
假如输入
2013-10-01
2010-08-30
2012-06-31
2013-05-31
1998-09-12
0
应当输出
2013-10-01:he was fishing at that day.
2010-08-30:he was sleeping at that day.
2012-06-31:Error!
2013-05-31:he was sleeping at that day.
1998-09-12:Error!
相关问题:
匿名网友:
这是我的测试结果:可以识别不同的错误种类,包括日期格式错误,日期不存在等(空行也会被识别为错误):
Please type in date as yyyy-mm-dd for each line
the last line should be 0
warning:this program uses gets(),which is unsafe.
输入:
2013-10-01
2010-08-30
2012-06-31
2013-05-31
1998-09-12
nothing
0
输出:
2013-10-01:he was fishing at that day
2010-08-30:he was sleeping at that day.
2012-06-31:Error:date doesn't exist
2013-05-31:he was sleeping at that day.
1998-09-12:Error:date too early
:Error:wrong format
nothing:Error:wrong format
代码:
#include
#include
#include
#define NEW (node *)malloc(sizeof(node))
#define MAX_CHAR_IN_LINE 50
typedef struct node{
char* date;
node* next;
} node;
int lengOfString(char* string)
{
int length=0;
while(string[length]!='\0' && length < MAX_CHAR_IN_LINE)
length ++;
return length;
}
bool checkFormat(char* string)
{
int i=0;
while(string[i])
{
if(i!=4 && i!=7)
{
if(string[i]'9' )
return false;
}
else
{
if (string[i]!='-')
return false;
}
i++;
}
if(i!=10)
return false;
return true;
}
bool isLeapYear(int year)
{
if ((year % 4 == 0) && !(year % 100 == 0))
return true;
else if(year % 400 ==0)
return true;
return false;
}
int daysInMonth(int year,int month)
{
int table[12]={ 31,28,31,30,31,30,31,31,30,31,30,31};
if (isLeapYear(year))
table[1]=29;
return table[month-1];
}
int checkDate(char* string)
{
string[4]='\0';
string[7]='\0';
int year=atoi(string);
int month=atoi(&string[5]);
int day=atoi(&string[8]);
if(month>12 || month < 1 )
return -1;
if( day daysInMonth(year,month))
return -1;
if(year < 2000)
return -2;
int days=0;
int ite_year;
int ite_month;
for (ite_year=2000; ite_yeardate);
if(checkFormat(head->date))
{
int value=checkDate(head->date);
if (value==-1)
printf(Error:date doesn't exist\n);
if (value==-2)
printf(Error:date too early \n);
if (value==0)
printf(he was sleeping at that day.\n);
if (value==1)
printf(he was fishing at that day \n);
}
else
{
printf(Error:wrong format \n);
}
head=head->next;
}
}
int main()
{
printf(Please type in date as yyyy-mm-dd for each line\n);
printf(the last line should be 0\n);
node* head=NEW;
node* tail=head;
while(true)
{
char* input=(char*)malloc(MAX_CHAR_IN_LINE*sizeof(char));
gets(input);
if (strncmp(input,0,MAX_CHAR_IN_LINE)==0)
break;
int str_length=lengOfString(input+1);
char* date= (char*)malloc(sizeof(char)*str_length);
strcpy(date,input);
free(input);
node* entry=NEW;
entry->date=date;
entry->next=NULL;
tail->next=entry;
tail=entry;
}
printList(head->next);
return 0;
}
大家还关注:
C语言中国有句俗语叫做“三天打鱼两天晒网”求高手!!!
1个答案 - 提问时间: 2013-12-14 - 6个赞
问题说明:中国有句俗语叫做“三天打鱼两天晒网”,这句话用在Tomcat身上正好。原来...
回答:这是我的测试结果:可以识别不同的错误种类,包括日期格式错误,日期不存在等(空行也会被识别为错误):Please type in date as yyyy-mm-dd for each line the last line ... 2013-12-14
c语言 三天打鱼,两天晒网 中国有一句话:三天打鱼,两天晒网 某人从...
2个答案 - 提问时间: 2011-11-24
问:{ printf("打鱼"); }else { printf("晒网"); } }求高手看一下,有错误...
回答:请验证2010以内的哥德巴赫猜想:对于任何大于4的偶数均可以分解为两个素数之和。 2.有句俗话叫:“三天打鱼两天晒网”,某人从2011年1月1日起开始“三天打鱼两天... 2011-11-24
C语言编程三天打鱼两天晒网
1个答案 - 提问时间: 2018-11-06 - 5个赞
回答:中国有句俗语叫 “三天打鱼两天晒网 ”。某人从 1990年 1月 1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。 根据题意可以将解... 2018-11-6
c语言做三天打鱼,两天晒网
1个答案 - 18个赞
问:7-4 三天打鱼两天晒网(15 分) 中国有句俗语叫“三天打鱼两天晒网”。假...
回答:你使用的判断方式有误,是“或”的关系,不是“与”。“三天打鱼两天晒网”,可见它的周期是5天,每个周期中前三天打鱼,后两天晒网。以下是在手机上用易历知食... 2017-10-22
三天打鱼两天晒网问题
2个答案 - 提问时间: 2013-12-14 - 5个赞
问题说明:俗话说“三天打鱼两天晒网“。某渔夫从1990年1月1日开始” 三天打鱼两天...
回答:11.打鱼还是晒网 中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。 *问... 2013-12-14
C语言“三天打鱼两天晒网”问题
2个答案 - 提问时间: 2010-04-28 - 6个赞
问题说明:有道题不会,求详解:中国有句俗语叫“三天打鱼两天晒网”。某人从1990年...
回答:#include "stdio.h"#define YEAR 2000#define DAYS 365 int TotalDays(int year,int month,int day); int a[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; int main() { int totalday; ... 2010-4-28
C语言 三天打鱼两天晒网(1)
2个答案 - 提问时间: 2015-12-09
问题说明:Description中国有句俗语叫“三天打鱼两天晒网”。某人从2011年1月1日开...
回答:#include "stdio.h"int TotalDays(int month,int day);int a[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};int main(){ int totalday; int month,day; scanf("%d%d",&month,&day); ... 2015-12-9
c语言代码打鱼还是晒网 俗话说“三天打鱼两天晒网”。某人从1990年...
1个答案 - 提问时间: 2018-02-28 - 1个赞
回答:#include#define YEAR 2010 void main() { int year,month,day,y,days=0; int ... //用计算出的总天数除以5,求模 printf("%d年%d月%d日他在打鱼\n\n",year,month,... 2018-2-28
大一C语言编程
2个答案 - 提问时间: 2008-12-19 - 4个赞
问题说明:中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日开始“三天打...
回答:这个问题问过很多次了,这是以前写的,一个完整的c程序如下,win-tc和Dev-c++下... puts("◇ 打鱼还是晒网 ◇"); puts("◇ 中国有句俗语叫【三天打鱼两天晒网】。 ◇... 2018-11-19
3天打鱼 2天晒网 问题。
6个答案 - 提问时间: 2008-12-17 - 3个赞
问:中国有句俗语叫“三天打鱼两天晒网”。某人从1990年1月1日起开始“三天...
回答:字面意思是5天之中3天打鱼2天晒网。引申过来是说做事没有恒心和毅力,经常半途而废。 2008-12-17
问题推荐