1 #include <cstdio>
2 #include <string.h>
3 #include <ctype.h>
4 #include <vector>
5 using namespace std;
6
7 const int maxk=100,maxl=100;
8 char key[maxk][maxl],str[maxl],str2[maxl],ans[maxk][maxl];
9 int K,E,n=0,Max,l;
10
11 bool find(int x,int y)
12 {
13 for(int i=0;i<K;i++){
14 int j;
15 for(j=0;x+j<=y&&key[i][j];j++)
16 if(str[x+j]!=key[i][j])
17 break;
18 if(x+j>y&&!key[i][j])
19 return true;
20 }
21 return false;
22 }
23
24 int main()
25 {
26 #ifndef ONLINE_JUDGE
27 freopen("409.in","r",stdin);
28 freopen("409.out","w",stdout);
29 #endif
30
31 while(scanf("%d%d",&K,&E)==2){
32 l=Max=0;
33 printf("Excuse Set #%d\\n",++n);
34 getchar();
35
36 for(int i=0;i<K;i++)
37 gets(key[i]);
38 for(int i=0;i<E;i++){
39 scanf("%[^\\r\\n]",str);
40 memcpy(str2,str,sizeof(str));
41 getchar();
42 int a=0,b,count=0;
43 while(str[a]){
44 while(!isalpha(str[a])&&str[a])++a;
45 b=a;
46 while(isalpha(str[b])){str[b]=tolower(str[b]);++b;}
47 if(find(a,b-1))count++;
48 a=b;
49 }
50 if(count>Max){
51 Max=count;
52 memset(ans,0,sizeof(ans));
53 l=1;
54 memcpy(ans[l-1],str2,sizeof(str));
55 }
56 else if(count==Max)
57 memcpy(ans[l++],str2,sizeof(str));
58 }
59 for(int i=0;i<l;i++)
60 printf("%s\\n",ans[i]);
61 printf("\\n");
62 }
63
64 fclose(stdin);
65 fclose(stdout);
66 return 0;
67 }
68
|