ADA Noise
Submissions: 104   Accuracy:

37.5%

  Difficulty: Easy   Marks: 2

You are given a message string S consisting of lowercase English letters and a noise word “ada”. All words that can be formed by adding “da” any number of times at the end of noise is also considered as a noise. For example, the words “adada”, “adadadadada”, ”adada” are noise but “dada”, ”ad”, ”aad” are not considered noise. You are given with the message signal S and you have to move all the noise present in the message signal to the end (in the same order as they occur in the message S) so that the filter can truncate the noises from the end.

Input:
The first line contains a positive integer T denoting the number of test cases. Each of the next T lines contains a message string S.

Output:
For each test case print on a new line the new signal formed after moving all the noise at the end.

Constraints:
1 <= T <= 10^5
1 <= length (string) <= 10^5

Example:
Input:

3
heyadadahiadahi 
heyheyhello  
adaheyadada  

Output:
heyhihiadadaada 
heyheyhello 
heyadaadada 

Explanation:
For the 1st case: ”adada” and “ada” are the noises. Noises are moved to the end in the same order as they appear in the string S. There is no noise in the 2nd signal. For the 3rd case: “ada” and “adada” are the noises.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sajal Agrawal
Author: sajalagrawal


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.