句子中的单词的查找
先将每个单词存起来,然后逐个比较;并且把每个单词的长度存起来,会节省时间
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 struct node 4 { 5 char s[105]; 6 int num; 7 }a[25]; 8 int main() 9 { 10 int m, n, max, i, j, k, len, flag, x, p=1; 11 char str[25][100], c[100]; 12 int b[25]; 13 while(scanf("%d%d",&m,&n) != EOF) 14 { 15 getchar(); 16 memset(b, 0, sizeof(b)); 17 max = 0; 18 for(i = 0;i < m;i++) 19 { 20 gets(a[i].s); 21 a[i].num = strlen(a[i].s); 22 } 23 for(i = 0;i < n;i++) 24 { 25 gets(str[i]); 26 } 27 for(i = 0;i < n;i++) 28 { 29 j = 0; 30 while(str[i][j] != '\0') 31 { 32 if((str[i][j] >= 'A' && str[i][j] <= 'Z')||(str[i][j] >= 'a' && str[i][j] <= 'z')) 33 { 34 len=0; 35 while((str[i][j] >= 'A' && str[i][j] <= 'Z')||(str[i][j] >= 'a' && str[i][j] <= 'z')) 36 { 37 c[len] = str[i][j]; 38 len++; 39 j++; 40 } 41 for(k = 0;k < m;k++) 42 { 43 if(len == a[k].num) 44 { 45 flag=0; 46 for(x = 0; x < len; x++) 47 { 48 if(c[x] != a[k].s[x] && c[x] != a[k].s[x]+32&&c[x] != a[k].s[x]-32) 49 flag=1; 50 } 51 if(flag == 0) 52 b[i]++; 53 } 54 } 55 } 56 else 57 { 58 j++; 59 } 60 } 61 if(max < b[i]) 62 max = b[i]; 63 } 64 printf("Excuse Set #%d\n",p); 65 for(i = 0;i < n; i++) 66 { 67 if(b[i] == max) 68 puts(str[i]); 69 } 70 puts(""); 71 p++; 72 } 73 return 0; 74 }