當前位置:編程學習大全網 - 編程軟體 - C語言問題,從鍵盤輸入n個英語單詞。輸入格式為n,w1,w2,w3…wn,其中n表示隨後輸入的英語

C語言問題,從鍵盤輸入n個英語單詞。輸入格式為n,w1,w2,w3…wn,其中n表示隨後輸入的英語

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

typedef?struct?Link

{

int?num;

char?*p;

struct?Link?*next;

}Link;

void?Insert(Link?*head,char?*str)

{

while(head->next!=NULL)

{

head?=?head?->next;

if(strcmp(str,head->p)==0)?{?head->num++;?return?;}

}

Link?*tmp?=?(Link*)malloc(sizeof(Link));

tmp->p?=?(char?*)?malloc(sizeof(str));

strcpy(tmp->p,str);

tmp->num=1;

tmp->next=NULL;

head->next=tmp;

//?return?node;

}

void?print(Link?*head)

{

Link?*node?=?head->next;

while(node!=NULL)

{

printf("%s:%d\n",node->p,node->num);

node=node?->next;

}

}

int?main()

{

int?n;

Link?*head=(Link*)malloc(sizeof(Link*));

scanf("%d",&n);

while(n--)

{

char?tmp[100];

scanf("%s",tmp);

Insert(head,tmp);

}

print(head);

return?0;

}

  • 上一篇:作家雨果說過開啟人類智慧英語作文
  • 下一篇:整本書課程起什麽名字
  • copyright 2024編程學習大全網