Replace a word
Easy Accuracy: 46.22% Submissions: 2105 Points: 2

Given three strings ‘str’, ‘oldW’ and ‘newW’. The task is find all occurrences of the word ‘oldW’ and replace then with word ‘newW’.

Input:
The first lne of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains 3 strings str, oldW and newW respectively.

Output:
Replace all the occurrences of oldW with newW in str.

Constraints:
1<=T<=1000
1<=length of str<=1000
1<=length of oldW and newW<=length of str

Example:
Input:
2
xxforxx xx for xx
xx
geeks
india is the xx country
xx
best

Output:
geeksforgeeks geeks for geeks
india is the best country

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.