从早上9点搞到现在:
总结几点 1:要保证输出顺序不便
2:吸收多余空格;
3:题目最后一行输出有问题直接用EOF结束
4:key (aba) aaba...aba....abaaba....答案是一;
5:注意循环不要有死循环;
#include <iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#include<map>
#include<list>
#include<set>
#define INF 1<<28
using namespace std;
struct node
{
int sum,no;
char s[200];
char s1[200];
} str1[220];
char str[220][200];
int n,k,Case=1;
void pb(int i)
{
for(int j=0;str1[i].s1[j]!='\0';j++)
{
for(int l=0;l<n;l++)
{
int f=1,m;
for( m=0;str[l][m]!='\0';m++)
if(str[l][m]!=tolower(str1[i].s1[j+m]))
{
f=0;
break;
}
if(f==1&&((j==0&&(!isalpha(str1[i].s1[j+m])))||(j!=0&&(!isalpha(str1[i].s1[j-1]))&&(!isalpha(str1[i].s1[j+m])))))
{
str1[i].sum++;
// printf("m1=%c\n",str1[i].s1[j-1]);
// printf("m=%c\n",str1[i].s1[j+m]);
}
}
}
}
int cmp( void const *a, void const *b)
{
struct node *aa=( node*) a;
struct node *bb=( node*) b;
if((bb->sum)==(aa->sum))
return (aa->no)-(bb->no);
return (bb->sum)-(aa->sum);
}
int main()
{
while(scanf("%d%d",&n,&k)!=EOF)
{
memset(str1,0,sizeof(str1));
memset(str,0,sizeof(str));
for(int i=0; i<n; i++)
{
scanf(" %s",str[i]);
// for(int j=0;str[i][j]!='\0';j++)
// str[i][j]=tolower(str[i][j]);
}
getchar();
for(int i=0; i<k; i++)
{
int t=0,l=0;
while(1)
{
char c;
c=getchar();
if(c=='\n'||c==EOF) break;
str1[i].s1[l++]=c;
if(islower(c)) str1[i].s[t++]=c;
else if(isupper(c)) str1[i].s[t++]=tolower(c);
}
str1[i].s[t]='\0';
str1[i].sum=0;
str1[i].no=i;
str1[i].s1[l]='\0';
pb(i);
}
qsort(str1,k,sizeof(str1[0]),cmp);
// for(int i=0;i<k;i++)
// printf("%d ",str1[i].sum);
int MAX=str1[0].sum;
int t=1;
printf("Excuse Set #%d\n",Case);
Case++;
printf("%s\n",str1[0].s1);
while(str1[t].sum==MAX&&t<k)
{
printf("%s\n",str1[t].s1);
t++;
}
printf("\n");
}
return 0;
}