Code: Select all
1 2
dog
dog0dog
dog
Code: Select all
Excuse Set #1
dog0dog
Moderator: Board moderators
Code: Select all
1 2
dog
dog0dog
dog
Code: Select all
Excuse Set #1
dog0dog
Code: Select all
1 2
dog
dog?dog
dog
Code: Select all
Excuse Set #1
dog?dog
Code: Select all
1 2
dog
dog"dog
dog
Code: Select all
Excuse Set #1
dog"dog
Code: Select all
#include <stdio.h>
#include<string.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
int tc = 1;
int K,E;
int testCase = 1;
while((scanf("%d%d",&K,&E))!=EOF)
{
if((K==0) && (E==0))
break;
int i,j,k=0;
char *excuse[20];
char *keyWords[20];
char *statements[20];
int matchword[100] = {0};
int len,count = 0;
int max = 1;
for(i=0;i<K;i++)
{
char str[1000] = {'\0'};
scanf("%s",str);
len = strlen(str);
keyWords[i]=(char *)malloc(sizeof(char)*(len+1));
strcpy(keyWords[i],str);
}
for(i=0;i<E;i++)
{
char ch;
char str[1000] = {'\0'};
char sentence[1000] = {'\0'};
if(i==0)
{
getchar();
}
int c = 0;
int st = 0;
while((ch=getchar())!='\n')
{
if((isalpha(ch))||(ch==' '))
{
str[c] = tolower(ch);
c++;
}
sentence[st] = ch;
st++;
}
str[c] = '\0';
len = strlen(str);
excuse[i]=(char *)malloc(sizeof(char)*(len+1));
strcpy(excuse[i],str);
sentence[st] = '\0';
len = strlen(sentence);
statements[i]=(char *)malloc(sizeof(char)*(len+1));
strcpy(statements[i],sentence);
}
int previousmax = 1;
for(i=0;i<E;i++)
{
for(j=0;j<K;j++)
{
if(strstr(excuse[i],keyWords[j])!=NULL)
count++;
}
if(count>=max)
{
max = count;
if(previousmax<max)
{
if(k>0)
k--;
}
matchword[k] = i;
previousmax = max;
k++;
}
count = 0;
}
printf("Excuse Set #%d\n",testCase);
for(i=0;i<k;i++)
{
printf("%s\n",statements[matchword[i]]);
}
printf("\n");
testCase++;
for(i=0;i<K;i++)
{
free(keyWords[i]);
}
for(i=0;i<E;i++)
{
free(statements[i]);
free(excuse[i]);
}
}
return 0;
}