Dubstep

Practice this coding question on Coding Gurukul.

Problem statement

An audio archive stores song titles as uppercase words. During a remix export, the separator token WUB was inserted between neighboring words, possibly several times, and may also have been added at the beginning or end. The original words themselves never contained that token. Your task Recover the original sequence of words from the encoded string. Treat each complete occurrence of WUB as a separator, merge consecutive separators, and discard separators before the first word or after the last word. Print the recovered words with exactly one space between them and no leading or trailing spaces. Preserve every other character and keep the original word order. A single W or the fragment WU inside a word is ordinary text, not a separator. At least one original word is guaranteed to remain. Worked example The encoding WUBHELLOWUBWUBWORLDWUB starts and ends with separator tokens and contains two between its words. Removing the outer tokens and combining the middle tokens gives HELLO WORLD. The plain input MUSIC already needs no changes.

Input format

One nonempty encoded string on one line.

Output format

Print the recovered words separated by single spaces.

Constraints

1 <= encoded length <= 200; uppercase English letters only; at least one word; original words do not contain WUB.

Sample input

WUBHELLOWUBWUBWORLDWUB

Sample output

HELLO WORLD

Sign in to run or submit a solution in C++, Java or Python.

Loading Coding Gurukul…