显示代码纯文本
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std;
string s[220],sa,ss,sss,ssa;
int u,maxx;
bool f[200003];
bool find(string s1,int h)
{
for(int i=1;i<=u;++i)
{
if(s[i].length()==h)
{
if(s[i]==s1)
return true;
}
}
return false;
}
int main()
{ freopen("prefix.in","r",stdin);
freopen("prefix.out","w",stdout);
while(cin>>ss&&ss!=".")
s[++u]=ss;
while(cin>>sss)
sa+=sss;
sa='.'+sa;
f[0]=1;
int len=sa.length();
int tr;
for(int j=1;j<=len-1;++j)
for(int i=j-1,tr=1;i>=0&&tr<=10;--i,++tr)
if(f[i]==1)
{
ssa=sa.substr(i+1,j-i);
int cx=ssa.length();
if(find(ssa,cx))
{
f[j]=1;
maxx=j;
break;
}
}
cout<<maxx;
//system("pause");
}