http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1756
View Code
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 using namespace std; 7 char str[100010][101]; 8 int cmp(const void *s1,const void *s2) 9 { 10 return(strcmp((char*)s1,(char*)s2)); 11 } 12 int main() 13 { 14 char c; 15 16 int flag=1; 17 int n=0,k=0,i; 18 char str1[101]; 19 while(~scanf("%c",&c)) 20 { 21 if((c>='a'&&c<='z')||(c>='A'&&c<='Z')) 22 { 23 flag=0; 24 if(c<='Z'&&c>='A') 25 str[n][k]=c+32; 26 else 27 str[n][k]=c; 28 k++; 29 } 30 else 31 { 32 if(flag==0) 33 { 34 str[n][k]='\0'; 35 n++; 36 k=0; 37 } 38 flag++; 39 } 40 } 41 qsort(str,n,sizeof(str[0]),cmp);//快排对字符串排序 42 strcpy(str1,str[0]); 43 puts(str[0]); 44 for(i=1;i<n;i++) 45 { 46 if(strcmp(str1,str[i])!=0) 47 { 48 puts(str[i]); 49 strcpy(str1,str[i]); 50 } 51 } 52 return 0; 53 }