不知道为什么一直ME,,,
其实我觉得我的板子还挺好的把,,,
改了很久了
我都把我开的数组放别人ac代码里面都不对,,,,
# include<iostream>
# include<cstdio>
# include<queue>
# include<cstring>
# include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
const int N=200*500+1;
const int maxc = 128;
int cnt;
int ch[N][maxc];
int f[N];
int val[N];
//int last[N];
int ans;
bool vis[504];
void init()
{
cnt=0;
memset(ch,0,sizeof(ch));
memset(val,0,sizeof(val));
}
int idx(char x)
{
return x;
}
void insertt(string p,int id)
{
int n=p.size();
int root=0;
for(int i=0; i<n; i++)
{
int c=idx(p[i]);
if(!ch[root][c])
{
ch[root][c]=++cnt;
}
root=ch[root][c];
}
val[root] = id;
}
void getFail()
{
queue<int>q;
f[0]=0;
for(int i=0; i<maxc; ++i)
if(ch[0][i])
{
f[ch[0][i]]=0;
// last[ch[0][i]]=0;
q.push(ch[0][i]);
}
while(!q.empty())
{
int r=q.front();
q.pop();
for(int i=0; i<maxc; ++i)
{
int u = ch[r][i];
if(!u)
{
ch[r][i]=ch[f[r]][i];
continue;
}
q.push(u);
int v = f[r];
while(v && !ch[v][i]) v = f[v];
f[u] = ch[v][i];
// last[u] = val[f[u]]? f[u] :last[f[u]];
}
}
}
void get(int now)
{
while(now)
{
if(val[now])
{
vis[val[now]]=1;
ans = 1;
}
now = f[now];
// now = last[now];
}
}
void match(string p)
{
int n=p.size();
int u=0;
for(int i=0; i<n; i++)
{
int c=idx(p[i]);
u=ch[u][c];
//if(val[u])
get(u);
// else if(last[u]) get(last[u]);
}
}
int main()
{
int n,m;
scanf("%d",&n);
init();
ans = 0;
string p;
for(int i=1; i<=n; ++i)
{
cin>>p;
insertt(p,i);
}
getFail();
scanf("%d",&m);
int num = 0;
for(int i=1; i<=m; i++)
{
string x;
cin>>x;
memset(vis,0,sizeof(vis));
ans = 0;
match(x);
if(ans)
{
printf("web %d:",i);
for(int i=1; i<=n; i++)
if(vis[i])
printf(" %d",i);
num++;
printf("\n");
}
}
printf("total: %d\n",num);
return 0;
}