题目描述
(线性表)设键盘输入n个英语单词,输入格式为n, w1, w2, …,wn,其中n表示随后输入英语单词个数,试编一程序,建立一个单向链表,实现:如果单词重复出现,则只在链表上保留一个。
输入
4
now come now please
输出
now come please
样例输入
3
go come keep
样例输出
go come keep
参考代码
#include <stdio.h>
#include <string.h>
struct List
{
char data[100][20];
int length;
}
;
int main(void)
{
struct List words;
int n;
int fl = 0;
int j = 0;
int is = 0;
scanf("%d", &n);
while (n)
{
scanf("%s", words.data[fl]);
int i = 0;
is = 0;
while (i < fl)
{
if (strcmp(words.data[i], words.data[fl]) == 0)
{
is = 1;
break;
} else
{
++i;
}
}
if (is)
{
;
} else
{
++fl;
}
--n;
}
for (j = 0; j < fl; ++j)
{
printf("%s ", words.data[j]);
}
printf("n");
return 0;
}
解析
暂无