Censoring
Time limit1sMemory limit256 MB
Repeatedly delete the leftmost occurrence of any of N forbidden words from string S until none remains and print the result.
- Level
Medium7 of 10
- Topics
- String matching, Stack, Simulation
- Solved
- No attempts yet
Problem
One issue of a magazine has been flattened into a single string made of lowercase letters. Some words must not appear in it, so the censored words to have to be deleted from .
Censoring works like this. Find the occurrence of a censored word in that starts at the smallest index, and delete that occurrence. Repeat until contains no occurrence of any censored word. Deleting one occurrence joins the characters around it, so a censored word that was not there before can appear.
No censored word is a substring of another censored word. At every step the occurrence with the smallest start index is therefore unique.
Print after censoring stops.
Input
The first line contains the string . It consists of lowercase letters and its length is at most .
The second line contains , the number of censored words.
Each of the next lines contains one censored word, to in order. Every word consists of lowercase letters, and the total length of the words is at most .
Output
Print after every deletion is done. never becomes empty during the process.