uva 10815
注意:主要的还是输入的问题,刚开始想的是直接读入字符串,但是又要将字符串分割成一个一个的单词,但是C语言没有这样的函数,所以后来在网上看到一个这样的输入方法,能巧妙的读入每一个字符,并将他们都转成小写,值得推荐阿。
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
char word[50005][205];
int cmp_str(void* _a,void* _b){
char* a=(char* )_a;
char* b=(char* )_b;
return strcmp(a,b);
}
int main(){
char temp[205],ch;
int i,j;
i=j=0;
while((ch=getchar())!=EOF){
if(isalpha(ch)){
ch=tolower(ch);
temp[j]=ch;
j++;
}else{
if(j>0){
temp[j]='\0';
strcpy(word[i],temp);
i++;
}
j=0;
}
}
qsort(word,i,sizeof(word[0]),cmp_str);
printf("%s\n",word[0]);
for(j=1;j<i;j++){
if(strcmp(word[j],word[j-1])==0)
continue;
printf("%s\n",word[j]);
}
return 0;
}