#P3121. Magazine Article Censorship
Magazine Article Censorship
Magazine Article Censorship
FJ has transcribed all the articles from a magazine into a string (s) of length at most (10^5). He also has a list of (n) words (t_1, t_2, \ldots, t_n). FJ wants to remove these words from (s) by performing the following operation repeatedly:
- Find the occurrence of any word from the list which appears earliest in (s) (i.e. with the smallest starting index).
- Delete that occurrence from (s).
Note that deleting a word may cause another word from the list to appear. The process stops when no word from the list appears in (s).
It is guaranteed that no word in the list is a substring of another, which ensures that if an occurrence exists in (s), its starting position is unique.
inputFormat
The input consists of multiple lines. The first line contains the string (s).
The second line contains an integer (n), the number of words in the list.
Then follow (n) lines, each containing one word (t_i) from the list.
outputFormat
Output the final string (s) after performing all the removals.
sample
abcde
2
bc
de
a