用凡科做的网站要钱吗,wordpress支付下载,徐州市建设局交易网站,ui设计原型图病毒侵袭持续中 上一题是求出现多少病毒输出病毒序号#xff0c;而这题输出每个病毒出现的次数。这题有字典树基础都能做出来#xff0c;把叶子节点用相应的编号标记起来#xff0c;匹配的时候遍历到叶子节点用一个数组把次数存起来就行了。 有了前几题的教训直接用静态树做… 病毒侵袭持续中 上一题是求出现多少病毒输出病毒序号而这题输出每个病毒出现的次数。这题有字典树基础都能做出来把叶子节点用相应的编号标记起来匹配的时候遍历到叶子节点用一个数组把次数存起来就行了。 有了前几题的教训直接用静态树做用C交果然不会错 const int N129;
char str[2000001],s[1001][55],v[1001];
int head,tail,cnt;
struct tree
{int f;tree *fail;tree *next[N];
}*q[50001],*root,memory[50001];
void insert(int i,char *s)
{tree *proot;while(*s!\0){int id(int)(*s);if(p-next[id]NULL) p-next[id]memory[cnt];pp-next[id];s;}p-fi;
}
void build()
{root-failNULL;q[head]root;while(head!tail){tree *tempq[tail];tree *pNULL;for(int i0; iN; i)if(temp-next[i]){if(temproot) temp-next[i]-failroot;else{ptemp-fail;while(p!NULL){if(p-next[i]){temp-next[i]-failp-next[i];break;}pp-fail;}if(pNULL) temp-next[i]-failroot;}q[head]temp-next[i];}}
}
void find(char *s)
{tree *proot;int ans0;while(*s!\0){int id(int)(*s);while(p-next[id]NULLp!root) pp-fail;pp-next[id];ppNULL?root:p;tree *tempp;while(temp!root){if(temp-f) v[temp-f];temptemp-fail;}s;}
}
int main()
{int n;while(~scanf(%d,n)){memset(memory,0,sizeof(memory));memset(v,0,sizeof(v));cntheadtail0;rootmemory[cnt];for(int i1; in; i){scanf(%s,s[i]);insert(i,s[i]);}build();scanf(%s,str);find(str);for(int i1; in; i)if(v[i]) printf(%s: %d\n,s[i],v[i]);}return 0;
}转载于:https://www.cnblogs.com/nyist-TC-LYQ/p/7208123.html