是吃假药了吗?
代码如下:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
char s[200005];
queue<int> q;
char mu[2000005];
struct zh{
int he[27];
int cuo,lu,lei;
}a[200005];
int zong=1;
int ji[200005];
int ru[200005];
int hoho[200005];
int jianshu(int x){
int qi=1;
int lenn=strlen(s+1);
for(int i=1;i<=lenn;i++){
// printf("%d",s[i]-'a');
int he=s[i]-'a';
if(a[qi].he[he]==0){
++zong;
a[qi].he[he]=zong;
}
qi=a[qi].he[he];
}
// printf("\n");
if(a[qi].lu==0){
a[qi].lu=x;
}
ji[x]=a[qi].lu;
}
void cuowu(){
for(int i=0;i<26;i++){
a[0].he[i]=1;
}
q.push(1);
// a[1].cuo=0;
while(q.empty()==0){
int haha=q.front();
q.pop();
int fann=a[haha].cuo;
for(int i=0;i<26;i++){
int hei=a[haha].he[i];
if(hei==0){
a[haha].he[i]=a[fann].he[i];
}
else{
a[hei].cuo=a[fann].he[i];
++ru[a[hei].cuo];
q.push(hei);
}
}
}
}
void zhao(){
int lenn=strlen(mu+1);
int qi=1;
for(int i=1;i<=lenn;i++){
int hehe=mu[i]-'a';
qi=a[qi].he[hehe];
++a[qi].lei;
}
}
void tuopu(){
for(int i=1;i<=zong;i++){
if(ru[i]==0){
q.push(i);
}
// printf("ru[%d]=%d **\n",i,ru[i]);
}
while(q.empty()==0){
int ha=q.front();
q.pop();
int hei=a[ha].cuo;
// printf("%d ^^\n",ha);
hoho[a[ha].lu]=a[ha].lei;
--ru[hei];
a[hei].lei+=a[ha].lei;
if(ru[hei]==0){
q.push(hei);
}
}
}
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
cin>>(s+1);
jianshu(i);
}
cin>>(mu+1);
cuowu();
zhao();
tuopu();
// printf("%d\n",zong);
for(int i=1;i<=n;i++){
printf("%d\n",hoho[ji[i]]);
}
return 0;
}