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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include<cctype> #include<cstring>
char key[20][30]; inline int (char word[], int K) { int j, count = 0; for (j = 0; j < K; j++) { if (!strcmp(key[j], word)) { count++; break; } }
return count; } int main() { int K, E, Case = 1; char excuse[20][75], str[75]; while (scanf("%d%d%*c", &K, &E) != EOF) { int i, j, count[20] = {}; char word[30]; for (i = 0; i < K; i++) gets(key[i]);
for (i = 0; i < E; i++) { gets(excuse[i]); for (j = 0; excuse[i][j]; j++) if (!isalpha(excuse[i][j])) str[j] = ' '; else str[j] = tolower(excuse[i][j]); excuse[i][j] = str[j] = NULL;
bool flag = false; int len = strlen(str), idx = 0; for (int s = 0; s < len; s++) { if (str[s] != ' ') { word[idx++] = str[s]; if (!flag) flag = true; } else if (flag) { flag = false; word[idx] = NULL; count[i] += check(word, K); idx = 0; } } if (str[len - 1] != ' ') { word[idx] = NULL; count[i] += check(word, K); } }
int max = 0; for (i = 0; i < E; i++) if (max < count[i]) max = count[i];
printf("Excuse Set #%dn", Case++); for (i = 0; i < E; i++) if (count[i] == max) puts(excuse[i]); putchar('n'); }
return 0; }
|
近期评论