String Censorship
Time limit1.5sMemory limit128 MB
Repeatedly delete the first then last occurrence of a pattern string from a text until it's absent, and output the final text.
- Level
Medium6 of 10
- Topics
- String matching, Stack, Simulation
- Solved
- No attempts yet
Problem
Given a text T and a forbidden word A, remove occurrences of A by repeating the following procedure.
- If the current text does not contain
A, stop. - Delete the first occurrence of
Ain the current text. - If the current text does not contain
A, stop. - Delete the last occurrence of
Ain the current text. - Go back to step 1.
Write a program that prints the text remaining after the whole procedure finishes.
Input
The first line contains the word A. The second line contains the text T.
Both A and T consist only of lowercase English letters. The length of A is at most 25, and the length of T is at most 300,000.
Output
Print the text remaining after all censorship steps are complete.