55分了
现在6-10RE了,咋办呐qwq
~~~
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int ch[150000][26],fail[150000],num[150000],ans[150000];
string T,in[155];
int n,cnt;
void s_insert(string ss,int order)
{
int now=0;
for(int i=0;i<ss.length();i++)
{
if(!ch[now][ss[i]-'a'])
ch[now][ss[i]-'a']=++cnt;
now=ch[now][ss[i]-'a'];
}
num[now]=order;
}
void s_build()
{
queue<int> dui;
for(int i=0;i<26;i++)
if(ch[0][i])
dui.push(ch[0][i]);
while(!dui.empty())
{
int now=dui.front();
dui.pop();
for(int i=0;i<26;i++)
if(ch[now][i])
{
fail[ch[now][i]]=ch[fail[now]][i];
dui.push(ch[now][i]);
}
else
ch[now][i]=ch[fail[now]][i];
}
}
void s_search()
{
int now=0;
for(int i=0;i<T.length();i++)
{
now=ch[now][T[i]-'a'];
for(int j=now;j;j=fail[j])
ans[num[j]]++;
}
}
int main()
{
scanf("%d",&n);
while(n!=0)
{
memset(fail,0,sizeof(fail));
memset(num,0,sizeof(num));
memset(ans,0,sizeof(ans));
memset(ch,0,sizeof(ch));
for(int i=1;i<=n;i++)
{
cin>>in[i];
s_insert(in[i],i);
}
cin>>T;
s_build();
s_search();
int maxn=0;
for(int i=1;i<=n;i++)
maxn=max(maxn,ans[i]);
cout<<maxn<<endl;
for(int i=1;i<=n;i++)
if(ans[i]==maxn)
cout<<in[i]<<endl;
cin>>n;
}
return 0;
}
by 3493441984zz @ 2018-11-24 14:22:40
这个题目数据加强了好像没改题面。。。
by 3493441984zz @ 2018-11-24 14:38:54