就是枚举吧 看当前i位置是否能达到
/*
ID: your_id_here
PROG: prefix
LANG: C++
*/
#include <iostream>
#include<cstdio>
#include<stdlib.h>
#include<cstring>
#include<algorithm>
using namespace std;
char p[210][12],ss[200010];
int f[200010];
int main()
{
freopen("prefix.in","r",stdin);
freopen("prefix.out","w",stdout);
int i,j,k,g=0,t=0,o;
char s[12],c;
while(scanf("%s",s)!=EOF)
{
if(strcmp(s,".")==0)
break;
g++;
strcpy(p[g],s);
}
while(cin>>c)
{
if(c=='#')
break;
if(c!='\n')
{
ss[t] = c;
t++;
}
}
f[0] = 1;
int ma = 0;
for(i = 1 ; i <=t ; i++)
{
for(j = 1; j <= g ; j++)
{
k = strlen(p[j]);
if(i>=k)
{
for(o = 0 ; o < k ; o++)
if(ss[i-k+o]!=p[j][o])
break;
if(o==k&&f[i-k])
{
f[i] = 1;
if(i>ma)
ma = i;
}
}
}
}
cout<<ma<<endl;
fclose(stdin);
fclose(stdout);
return 0;
}