显示代码纯文本
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
using namespace std;
vector<string>e;
string a;
const int LEN=200000+1;
bool dp[LEN];
int main(){
freopen("prefix.in","r",stdin);
freopen("prefix.out","w",stdout);
string t;
while(cin>>t&&t!=".") e.push_back(t);
while(cin>>t) a+=t;
dp[0]=1;
for(int i=1;i<=a.size();i++)
for(int j=0;j<e.size();j++)
{
// if(i-(int)e[j].size()>=0&&dp[i-e[j].size()]) cout<<a.substr(i-e[j].size(),e[j].size())<<' '<<e[j]<<' '<<(a.substr(i-e[j].size(),e[j].size())==e[j])<<endl;
if(i-(int)e[j].size()>=0&&dp[i-e[j].size()]&&a.substr(i-e[j].size(),e[j].size())==e[j]) dp[i]=1;
}
for(int i=a.size();i>=0;i--) if(dp[i]) {
cout<<i;
return 0;
}
}