题意:找出字符串中关键字符最多的那串字符,如果关键字符相等,则相等的都要输出
思路:就是一个一个关键字符慢慢找,开一个vis数组,记录每个字符串的关键字符的数量,不断更新。
#include<stdio.h>
#include<string.h>
#include<ctype.h>
char word[25][25], s[25][100], str[25][100];
int vis[25];
int n, m;
void num(char *s, int x){
for(int i = 0; i < n; i++)
if(strcmp(s, word[i]) == 0)
vis[x]++;
}
int main(){
int max, t = 0, k;
char c[25];
while (scanf("%d %d", &n, &m) != EOF){
getchar();
max = 0, k = 0;
memset(vis, 0, sizeof(vis));
for(int i = 0; i < n; i++)
gets(word[i]);
for(int i = 0; i < m; i++){
gets(s[i]);
strcpy(str[i], s[i]);
}
for(int i = 0; i < m; i++){
int len = strlen(s[i]);
for(int j = 0; j < len; j++){
if (!isalpha(s[i][j])){
c[k] = '\0';
num(c, i);
if (max < vis[i])
max = vis[i];
k = 0;
continue;
}
s[i][j] = tolower(s[i][j]);
c[k++] = s[i][j];
}
}
printf("Excuse Set #%d\n", ++t);
for(int i = 0; i < m; i++)
if (max == vis[i])
puts(str[i]);
printf("\n");
}
return 0;
}