HDU 5880 AC automatic machine

Source: Internet
Author: User

Family View

Time limit:3000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 175 Accepted Submission (s): 20


problem DescriptionSteam is a digital distribution platform developed by Valve Corporation offering digital Rights Management (DRM), mult iplayer Gaming and social networking services. A Family view can help the Prevent your children access to some content which is not suitable for them.

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

For example, T was: "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 is: "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 integerN, represneting the size of the forbidden words listP. Each line of the nextNLines contains a forbidden wordsPI(1≤|pi | ≤1000000,∑| pi | ≤1000000) wherePi only contains lowercase letters.

The last line contains a string T (| T| ≤1000000). 

OutputFor each case output of the sentence in a line. 

Sample Input13trumprioDonald John Trump (born June, 1946) is an American businessman, television personality, author, Politicia N, and the Republican Party nominee for president of the the same States in the election. He is chairman of the Trump Organization, which are the principal holding company for his real estate ventures and other BU Siness interests. 

Sample OutputD*nald J*HN * * * * * * (B*rn June, 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 same states in the 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 BU Siness interests. 

SourceACM/ICPC Asia Regional Qingdao Online

/*hdu 5880 ac automaton problem: give you some substrings and then block them out in the article. Solve: Sweep with an AC automaton and then lay the mark on the place where it needs to be shielded hhh-2016-09-17 20:51:55*/#include < iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <vector> #include <queue>using namespace Std;const int maxn = 1001000;char s[maxn];int dis[maxn];int ans[maxn];struct Tire{int NEX [1001000]    [27],fail[1001000],ed[1001000];    int root,l;        int NewNode () {for (int i = 0; i <; i++) nex[l][i] = 1;        ed[l++] = 0;    return L-1;    } void Ini () {L = 0,root = NewNode ();    } int cha (char x) {return x ' a ';        } void Inser (char buf[]) {int len = strlen (BUF);        int now = root;            for (int i = 0; i < len; i++) {int ta = cha (buf[i]);            if (nex[now][ta] = =-1) nex[now][ta] = NewNode ();        now = Nex[now][ta];        } Ed[now] = 1;    Dis[now] = len; } void Build () {QUeue<int >q;        Fail[root] = root;            for (int i = 0; i < i++) if (nex[root][i] = = 1) nex[root][i] = root;                else {Fail[nex[root][i]] = root;            Q.push (Nex[root][i]); The while (!q.empty ()) {int now = Q.front ();//if (Ed[fail[now])//Ed[now            ] = 1;            Q.pop (); for (int i = 0; i < i++) {if (nex[now][i] = = 1) nex[now][i] = Nex[fail [Now]]                [i];                    else {Fail[nex[now][i]] = nex[fail[now]][i];                Q.push (Nex[now][i]);        }}}} void solve (char* str) {int cur = root;        int len = strlen (str);        int index;                for (int i = 0; i < len; i++) {if (str[i]>= ' A ' &&str[i]<= ' Z ') {    index = str[i]-' A ';        } else if (str[i]>= ' a ' &&str[i]<= ' Z ') {index = str[i]-' a ';            } else continue;            cur = Nex[cur][index];            int TP = cur;                    while (TP! = root) {if (ED[TP]) {ans[i+1]-= 1;                    ANS[I-DIS[TP]+1] + = 1;                Break            } TP = FAIL[TP]; }        }    }};    Tire Ac;int Main () {int t;    int n;    scanf ("%d", &t);        while (t--) {scanf ("%d", &n);        Ac.ini ();            for (int i=0; i<n; i++) {scanf ("%s", s);        Ac.inser (s);        } ac.build ();        GetChar ();        Gets (s);//puts (s);        memset (ans, 0, sizeof (ans));        Ac.solve (s);        int len = strlen (s);        Long long int tans = 0;            for (int i=0; i<len; i++) {tans + = ans[i]; if (Tans <= 0) printF ("%c", S[i]);        else printf ("*");    } printf ("\ n"); } return 0;}

  

HDU 5880 AC automatic machine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.