Steam is a digital distribution platform developed by Valve Corporation offering digital rights management (DRM), multiplayer gaming and social networking services. A family view can help you to prevent your children access to some content which are not suitable for them.

Take an MMORPG game as an example, given a sentence T, and a list of forbidden words {P}, your job is to use '*' to subsititute all the characters, which is a part of the substring matched with at least one forbidden word in the list (case-insensitive).

For example, T is: "I love Beijing's Tiananmen, the sun rises over Tiananmen. Our great leader Chairman Mao, he leades us marching on."

And {P} is: {"tiananmen", "eat"}

The result should be: "I love Beijing's *********, the sun rises over *********. Our gr*** leader Chairman Mao, he leades us marching on."

InputThe first line contains the number of test cases. For each test case: 
The first line contains an integer nn, represneting the size of the forbidden words list PP. Each line of the next nn lines contains a forbidden words Pi (1≤|Pi|≤1000000,∑|Pi|≤1000000)Pi (1≤|Pi|≤1000000,∑|Pi|≤1000000) where PiPi only contains lowercase letters.

The last line contains a string T (|T|≤1000000)T (|T|≤1000000).OutputFor each case output the sentence in a line.Sample Input

1
3
trump
ri
o
Donald John Trump (born June 14, 1946) is an American businessman, television personality, author, politician, and the Republican Party nominee for President of the United States in the 2016 election. He is chairman of The Trump Organization, which is the principal holding company for his real estate ventures and other business interests.

Sample Output

D*nald J*hn ***** (b*rn June 14, 1946) is an Ame**can businessman, televisi*n pers*nality, auth*r, p*litician, and the Republican Party n*minee f*r President *f the United States in the 2016 electi*n. He is chairman *f The ***** *rganizati*n, which is the p**ncipal h*lding c*mpany f*r his real estate ventures and *ther business interests.


AC自动机+sum数组扫描记录“*段”

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
const int maxn=;
int Next[maxn][],End[maxn],fail[maxn],h[maxn];
int cnt,root=,ans;
int q[],tail,head;
int a[maxn],sum[maxn];
char c[maxn] ;
void _init()
{
//不要memset只要200ms
// memset(a,0,sizeof(a));
ans=;cnt=;fail[root]=-;//root的fail不能等于本身,不然不能重新开始。
head=tail=;End[root]=;
for(int i=;i<;i++) Next[root][i]=;
}
void _insert(char s[])
{
int L=strlen(s);
int Now=root;
for(int i=;i<L;i++){
if(!Next[Now][s[i]-'a']) {
Next[Now][s[i]-'a']=++cnt;
fail[cnt]=;
End[cnt]=;
for(int i=;i<;i++) Next[cnt][i]=;
h[cnt]=h[Now]+;
a[cnt]=;
}
Now=Next[Now][s[i]-'a'];
}
End[Now]++;
}
void _build()//bfs
{
q[++head]=root;
while(tail<head){
int Now=q[++tail];
for(int i=;i<;i++){
if(Next[Now][i]){
if(Now==root) fail[Next[Now][i]]=root;
else{
int p=fail[Now];
while(p){//给儿子们找对象
if(Next[p][i]){
fail[Next[Now][i]]=Next[p][i];
break;//找到了就停止
}
p=fail[p];//配对
}
if(!p) {
fail[Next[Now][i]]=root;//重新开始
}
}
q[++head]=Next[Now][i];
}
}
}
}
void _query()
{
int L=strlen(c);
int Now=root;
for(int i=;i<L;i++){
int x=-;
if(c[i]>='A'&&c[i]<='Z') x=c[i]-'A';
if(c[i]>='a'&&c[i]<='z') x=c[i]-'a';
if(x==-) {
Now=root;
continue;
}
while(Now!=root&&!Next[Now][x]) Now=fail[Now];
Now=Next[Now][x];
if(!Now) Now=root;//即使失败,也不气馁,一切从零开始
int tmp=Now;
while(tmp!=root){
if(End[tmp]>){
a[i-h[tmp]+]-=;
a[i+]+=;
break;
}
tmp=fail[tmp];
}
}
sum[]=a[];a[]=;
for(int i=;i<L;i++){
sum[i]=sum[i-]+a[i];
a[i]=;
}
for(int i=;i<L;i++) {
if(sum[i]<) putchar('*');
else putchar(c[i]);
}
putchar('\n');
}
int main()
{
char s[maxn];
int n,j,i,T;
scanf("%d",&T);
while(T--){ _init();
scanf("%d",&n);
for(i=;i<=n;i++){
scanf("%s",s);
_insert(s);//单词
}
s[]=getchar();
gets(c); _build();
_query();//文章
}
return ;
}

 
												

HDU5880 Family View ac自动机第二题的更多相关文章

  1. HDU 2222 AC自动机模板题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...

  2. HDU 3065 (AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 题目大意:多个模式串,范围是大写字母.匹配串的字符范围是(0~127).问匹配串中含有哪几种模 ...

  3. HDU 2896 (AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2896 题目大意:多个模式串.多个匹配串.其中串的字符范围是(0~127).问匹配串中含有哪几个模式串 ...

  4. HDU 2222(AC自动机模板题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题 ...

  5. HDU3695(AC自动机模板题)

    题意:给你n个字符串,再给你一个大的字符串A,问你着n个字符串在正的A和反的A里出现多少个? 其实就是AC自动机模板题啊( ╯□╰ ) 正着query一次再反着query一次就好了 /* gyt Li ...

  6. hdu2222 KeyWords Search AC自动机入门题

    /** 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222 题意:题意:给定N(N <= 10000)个长度不大于50的模式串,再给定一个长度为L ...

  7. HDu-2896 病毒侵袭,AC自动机模板题!

    病毒侵袭 模板题,不多说了.. 题意:n个不同的字符串分别代表病毒特征,给出m次查询,每次一个字符串(网址),求这个字符串中有几个病毒特征,分别从大到小输出编号,最后输出所有的带病毒网址个数.格式请看 ...

  8. [Bzoj3940] [AC自动机,USACO 2015 February Gold] Censor [AC自动机模板题]

    AC自动机模板题(膜jcvb代码) #include <iostream> #include <algorithm> #include <cstdio> #incl ...

  9. hdu 2222(AC自动机模版题)

    Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

随机推荐

  1. codeforces 578c - weekness and poorness - 三分

    2017-08-27 17:24:07 writer:pprp 题意简述: • Codeforces 578C Weakness and poorness• 给定一个序列A• 一个区间的poornes ...

  2. Python学习札记(八) Basic5 循环

    参考:循环 Note: A.for···in循环: 1.for x in ...循环就是把每个元素代入变量x,然后执行缩进块的语句. eg. #!/usr/bin/env python3 list_A ...

  3. Java常用的几种线程池

    常用的几种线程池 5.1 newCachedThreadPool 创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活回收空闲线程,若无可回收,则新建线程. 这种类型的线程池特点是: 工作线程的创 ...

  4. HDU 1827 Summer Holiday

    http://acm.hdu.edu.cn/showproblem.php?pid=1827 题意: 听说lcy帮大家预定了新马泰7日游,Wiskey真是高兴的夜不能寐啊,他想着得快点把这消息告诉大家 ...

  5. codeforces291E Tree-String Problem

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  6. webstorm拉取git代码

    在webstorm中VCS → git → clone → url就是你的git代码地址,parent Directory(你要放到的目录),Directiory Name(起一个项目名称)

  7. kotlin for android----------MVP模式下(OKHttp和 Retrofit+RxJava)网络请求的两种实现方式

    今天要说的干货是:以Kotlin,在MVP模式下(OKHttp和 Retrofit+RxJava)网络请求两种实现方式的一个小案例,希望对大家有所帮助,效果图: Retrofit是Square公司开发 ...

  8. PyCharm在win10的64位系统安装实例

    搭建环境 1.win10_X64,其他Win版本也可以. 2.PyCharm版本:Professional-2016.2.3. 搭建准备 1.到PyCharm官网下载PyCharm安装包. 2.选择W ...

  9. ZOJ-2972-Hurdles of 110m(线性dp)

    Hurdles of 110m Time Limit: 2 Seconds      Memory Limit: 65536 KB In the year 2008, the 29th Olympic ...

  10. elasticsearch实现网站搜索

    使用elasticsearch 实现网站搜索,可以支持商品搜索,筛选项过滤搜索 ,价格排序, 打分 筛选项聚合,还有其他综合排序 后续推出搜索人工干预排序,根据销量,好评率,售卖率 进行全方位的搜索实 ...