c语言第四版第8章答案,C语言答案第8章.doc

C语言答案第8章

第8章

[习题-1]/*c8_1.c*/

#include

struct book

{

char title[20];

char aditor[10];

int year;

int month;

char flag;

}liber[10];

void main( )

{

int i;

for(i=0;i<10;i++)

{

rintf("Input book title:\n");

scanf("%s",liber[i].title);

printf("Input book aditor:\n");

scanf("%s",liber[i].aditor);

printf("Input print date,year and month :\n");

scanf("%d%d",&liber[i].year,&liber[i].month);

printf("Input book information:\n");

scanf("%c",&liber[i].flag);

}

for(i=0;i<10;i++) printf("%s,%s,%d-%d,%c\n",liber[i].title,liber[i].aditor,liber[i].year,liber[i].month,liber[i].flag);

}

[习题-2]/*c8_2.c*/

#include

#include

#include

struct list

{

char words[20];

int num;

struct list *next;

};

typedef struct list node;

typedef node *link;

void count(char *str)/*统计正文中单词个数*/

{

link ptr,head,ptrn,headnew;

int i=0,j=0,prei=0;

char temp[20];

ptr=(link)malloc(sizeof(node));

head=ptr;

ptr->next=NULL;

do

{

if(*(str+i)==' '||*(str+i)=='\0')

{/*出现一个单词*/

temp[j]='\0';

ptr=head;

while(ptr->next!=NULL)

{

if(strcmp(ptr->next->words, temp)==0)/*该单词已经出现*/

{

ptr->next->num++;

break;/*结束内层while循环*/

}

else

ptr=ptr->next;

}

if(ptr->next==NULL)/*该单词是新单词*/

{

ptr->next=(link)malloc(sizeof(node));

strcpy(ptr->next->words,temp);

ptr->next->num=1;

ptr->next->next=NULL;

}

if(*(str+i)=='\0') break; /*全部正文已经结束,跳出循环*/

j=0;

i++;

continue;

}

temp[j++]=str[i++];

}while(1);

ptrn=(link)malloc(sizeof(node));/*新建一个按照顺序排列的链表*/

headnew=ptrn;

ptrn->next=NULL;

ptr=head->next;

ptrn=headnew;

while(head->next!=NULL)

/*把head链表中的结点依次取出按照顺序链接到新的链表headnew中*/

{

while(ptrn->next!=NULL&&ptrn->next->num>=ptr->num)

ptrn=ptrn->next;

head->next=ptr->next;

ptr->next=ptrn->next;

ptrn->next=ptr;

ptr=head->next;

ptrn=headnew;

}

ptr=headnew->next;

while(ptr!=NULL){/*将排好序的结点输出*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值