#include <stdio.h>
#include <string.h>
int main() {
int MAX = 0;
char str[25][25], str1[25][25];
char str2[25][1700], str3[25][1700];
int m, n, t = 0;
//输入数据
while (scanf("%d%d", &m, &n) != EOF) {
MAX = 0;
getchar();
for (int i = 0; i < m; i++)
gets(str[i]);
for (int j = 0; j < n; j++)
gets(str2[j]);
/* // 检查输入是否正确保存数据
printf("%d %d\n", m, n);
for (int i = 0; i < m; i++)
puts(str[i]);
for (int j = 0; j < n; j++)
puts(str2[j]);
*/
// 把大写字符转换成小写
int i, j, len;
for (i = 0; i < m; i++) {
len = strlen(str2[i]);
for (j = 0; j < len; j++)
if (str2[i][j] >= 'A' && str2[i][j] <= 'Z')
str3[i][j] = str2[i][j] + 32;
else
str3[i][j] = str2[i][j];
}
/* for (i = 0; i < m; i++) {
len = strlen(str[i]);
for (j = 0; j < len; j++)
if (str[i][j] >= 'A' && str[i][j] <= 'Z')
str1[i][j] = str[i][j] + 32;
else
str1[i][j] = str[i][j];
}
*/
/* // 检查转换后是否正确保存数据
printf("%d %d\n", m, n);
for (int i = 0; i < m; i++)
puts(str[i]);
for (int j = 0; j < n; j++)
puts(str3[j]);
*/
int len_1, len_2, k, count = 0, sum;
for (i = 0; i < n; i++) { //句子
sum = 0;
// puts(str3[i]);
len_1 = strlen(str3[i]);
for (j = 0; j < m; j++) { //单词
len_2 = strlen(str[j]);
count = 0;
for (k = 0; k < len_1; k++) {
int s = 0, k_1 = k ;
while (str3[i][k_1] == str[j][s]) {
k_1++, s++;
if (s == len_2 && str3[i][k_1] < 'a' || str3[i][k_1] > 'z') {
count++;
}
}
}
// printf("%s = %d\n", str[j], count);
sum += count;
}
// printf("sum = %d\n\n", sum);
if (sum >= MAX)
MAX = sum;
}
printf("Excuse Set #%d\n", ++t);
for (i = 0; i < n; i++) { //句子
sum = 0;
len_1 = strlen(str3[i]);
for (j = 0; j < m; j++) { //单词
len_2 = strlen(str[j]);
count = 0;
for (k = 0; k < len_1; k++) {
int s = 0, k_1 = k ;
while (str3[i][k_1] == str[j][s]) {
k_1++, s++;
if (s == len_2 && str3[i][k_1] < 'a' || str3[i][k_1] > 'z') {
count++;
}
}
}
sum += count;
}
if (sum == MAX)
puts(str2[i]);
}
printf("\n");
}
return 0;
}
UVA 409 (暑假-字符串(2) -B - Excuses, Excuses!)
最新推荐文章于 2015-07-28 09:54:32 发布