uva10815 - Andy's First Dictionary
刚开始错了六七次,不过后来调用了库函数,进行字符串排序,就AC了,看来还是要掌握一些库函数,才能更迅速的写出完美的代码啊
下面是代码,聪明人一看就会懂得啦,对了,本体一个关键是,注意要把存储单词的数组开的大一些,我刚开始没注意到,导致RE了两次
View Code
1 #include<stdio.h> 2 #include<string.h> 3 #include<ctype.h> 4 #include<stdlib.h> 5 char word[100010][210] = {'\0'}; 6 int Comp(const void *p1,const void *p2) 7 { 8 return strcmp((char *)p2,(char *)p1); 9 } 10 int main() 11 { 12 int i, k = 0, top = 0;; 13 char ch; 14 while((ch = getchar()) != EOF) 15 { 16 if(isalpha(ch)) 17 word[top][k++] = tolower(ch); 18 else 19 { 20 if(isalpha(word[top][0])) 21 { 22 word[top++][k] = '\0'; 23 k = 0; 24 } 25 } 26 } 27 qsort(word,top,sizeof(word[0]),Comp); 28 for(i = top-1;i > -1; i--) 29 { 30 if(strcmp(word[i],word[i-1]) != 0) 31 puts(word[i]); 32 } 33 return 0; 34 }