Replace a word
Submissions: 1566   Accuracy:

39.28%

  Difficulty: Easy   Marks: 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

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

Contributor: Ayush Govil
Author: Ayush Govil 1


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.