#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <memory.h>
#define MAXLEN 5000
struct Word
{
char word[20];
};
struct Word w[MAXLEN];
struct Word wRecode, change;
int index = 0;
void insert ()
{
int isRepeat = 0,i;
for (i = 0; i < index; i++)
if (strcmp(wRecode.word, w[i].word) == 0)
isRepeat = 1;
if (!isRepeat)
{
w[index] = wRecode, index ++;
for (i = index - 1; i >= 1; i --)
{
if (strcmp(w[i].word, w[i - 1].word) == -1)
{
change = w[i];
w[i] = w[i - 1];
w[i - 1] = change;
}
}
}
}
int main()
{
int i, j;
char str[200] = {"\0"};
while (gets(str))
{
j = 0; int isWord = 0;
for (i = 0; str[i]; i ++)
{
if (isalpha(str[i]))
{
wRecode.word[j] = tolower(str[i]);
j ++;
isWord = 1;
continue;
}
else if (isWord)
{
insert();
j = 0, isWord = 0;
memset(wRecode.word, 0, strlen(wRecode.word));
}
}
if (isWord && str[i + 1] == '\0')
insert(), j = 0, isWord = 0, memset(wRecode.word, 0, strlen(wRecode.word));
memset(str, 0, strlen(str));
}
for (i = 0; i < index; i ++)
{
printf("%s\n", w[i].word);
}
return 0;
}
回目錄
回首頁
沒有留言 :
張貼留言