数据水,但是各种wa各种t各种re最后照着别人的改了改发现了毛病
数组做指针传入的时候系统是不知道传入后的数字的长度的如果用memset他就只会讲指针的地方清零
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
const int cha = ;
const int maxa = ;
int n, m, k;
struct Tire{
int next[maxa][cha], fail[maxa], end[maxa];
int root, L;
int newnode(){
for(int i = ; i < cha; i++){
next[L][i] = -;
}
end[L++] = ;
return L-;
}
void init(){
L = ;
root = newnode();
}
void insert(char buf[], int k){
int len = strlen(buf);
int now = root;
for(int i = ; i < len; i++){
if(next[now][buf[i]] == -)
next[now][buf[i]] = newnode();
now = next[now][buf[i]];
//printf("%d ", now);
}//puts("");
end[now] = k;
}
void build(){
queue<int>Q;
fail[root] = root;
for(int i = ; i < cha; i++){
if(next[root][i] == -)
next[root][i] = root;
else{
fail[next[root][i]] = root;
Q.push(next[root][i]);
}
}
while(!Q.empty()){
int now = Q.front();
Q.pop();
for(int i = ; i < cha; i++){
if(next[now][i] == -)
next[now][i] = next[fail[now]][i];
else{
fail[next[now][i]] = next[fail[now]][i];
Q.push(next[now][i]);
}
}
}
}
int ans[];
int solve(char *s, int id){
int now = ;
int flag = ;
memset(ans, , sizeof(ans));
for(int i = ; s[i]; i++){
now = next[now][s[i]];
int j = now;
while(j){
if(end[j]){//printf("*%d ", end[j]);
ans[end[j]] = true;
flag = ;
}
j = fail[j];
}
}
if(!flag) return ;
printf("web %d:",id);
for(int i = ;i <= n;i++)
if(ans[i])
printf(" %d",i);
printf("\n");
return ; }
};
char buf[];
Tire ac;
int main(){
scanf("%d", &n);
ac.init();
for(int i = ; i <= n; i++){
scanf("%s", buf);
ac.insert(buf, i);
}
ac.build();
scanf("%d", &m);
int sum = ;
for(int i = ; i <= m; i++){
scanf("%s", buf);
if(ac.solve(buf,i))
sum ++;
}
printf("total: %d\n",sum);
}
/*
abcdefg
bcdefg
cdef
de
e
ssaabcdefg */