


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include<stdio.h>#include<stdlib.h>#include<string.h>int n;char word[ 1000][10 ],sorted[ 1000][10 ];//字符比较函数int cmp_char(const void * _a, const void *_b){ char* a=(char*)_a ; char* b=(char*)_b ; return *a-* b;}int cmp_string(const void * _a,const void * _b){ char* a=(char *) _a; char* b=(char *) _b; return strcmp (a, b);}void main(){ int i; char s[10 ]; n=0 ; for(;;) { scanf ("%s",word[n ]); if(word [n][ 0]=='*' )break; n ++; } qsort(word ,n, sizeof(word [0]), cmp_string);// 给所有单词排序 for(i=0 ;i< n;i++) { strcpy (sorted[ i],word[i ]); qsort (sorted[ i],strlen(sorted [i]), sizeof(char ),cmp_char); } while(scanf("%s" ,s)== 1)// 持续督导文件结束 { int found =0; qsort (s, strlen(s ),sizeof(char),cmp_char ); for( i =0; i<n;i ++) if(strcmp (sorted[ i],s)==0 ) { found =1; printf ("%s ",word[i ]); } if(!found )printf( ":("); printf ("
"); }} |