http://poj.org/problem?id=1598
找出含所给关键字最多的那个句子
<span style="font-size:18px;">#include <stdio.h>
#include <string.h>
char keyword[25][25],excuses[25][75];
char temp[75];
void StringChangeLower(char* s) //大写字母转小写字母
{
int i;
for(i = 0; i < strlen(s); i++)
if(s[i] >= 'A' && s[i] <= 'Z')
s[i] += 32;
}
int StrSearch(char* p, char* q)//单词p在句子q里出现的次数
{
char t[75];
int i, j ,num = 0;
for(i=0;i<strlen(q);i++)
{
j = 0;
while(q[i] >= 'a'&&q[i] <= 'z')
{
t[j++] = q[i];
i++;
}
t[j] = '\0';
if(strcmp(p, t) == 0)
num++;
}
return num;
}
int main()
{
int i,j,k,e,keytimes[22], c=0,max;
while(scanf("%d %d",&k,&e)!=EOF)
{
max = 0;
for(i = 0;i < k; i++)
scanf("%s",keyword[i]);
getchar();
for(i = 0;i < e; i++)//遍历所给句子
{
gets(excuses[i]);
strcpy(temp, excuses[i]);
StringChangeLower(temp);
keytimes[i] = 0;
for(j = 0; j<k; j++)//对于每个句子,(第1个关键词多少次,第2个关键词多少次... 第k个关键词多少次,累加所有次数)
keytimes[i] += StrSearch(keyword[j],temp);
if(keytimes[i] > max)
max = keytimes[i];
}
printf("Excuse Set #%d\n",++c);
for(i=0; i < e; i++)
{
if(max == keytimes[i])
puts(excuses[i]);
}
printf("\n");
}
return 0;
}
</span>