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;
}