显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
using namespace std;
set<string> sets;
string str;
int len,maxlen;
bool f[200010]={true};
int main(void)
{
freopen("prefix.in","r",stdin);
freopen("prefix.out","w",stdout);
string temp="";
int i,j,c;
char ch[200]={0};
while (scanf("%s",&ch)==1)
{
if (ch[0]=='.')
break;
temp=ch;
sets.insert(temp);
}
while (scanf("%s",&ch)==1)
{
temp=ch;
str+=temp;
}
len=str.size();
str="#"+str;
for (i=1;i<=len;i++)
{
for (c=1,j=i-1;c<=10&&j>=0;c++,j--)/*error : ignored the tip "长度为 1..10"*/
{
if (f[j])
{
if (sets.find(str.substr(j+1,i-j))!=sets.end())
{
f[i]=true;
maxlen=i;
break;
}
}
}
}
printf("%d\n",maxlen);
return(0);
}