P17200 [GeeksforGeeks] Replace a word5553
普及-
题目描述

Given three strings S, oldW and newW. Find all occurrences of the word oldW in S and replace them with word newW.
Example 1:
Input:
S = "xxforxx xx for xx"
oldW = "xx"
newW = "Geeks"
Output:
"geeksforgeeks geeks for geeks"
Explanation:
Replacing each "xx" with
"Geeks" in S.
Example 2:
Input:
S = "india is the xx country"
oldW = "xx"
newW = "best"
Output:
"india is the best country"
Explanation:
Replacing each "xx" with
"best" in S.
Your Task:
You dont need to read input or print anything. Complete the function ReplaceAll() which takes S, oldW and newW as input parameters and returns the string S after replacing all oldW with newW.
Expected Time Complexity: O(n^{2})
Expected Auxiliary Space: O(1)
Constraints:
1<= |S| <=1000
1<= |oldW|, |newW| <=|S|

输入格式

见题面

输出格式

见题面

样例输入
S = "xxforxx xx for xx" oldW = "xx" newW = "Geeks"
样例输出
"geeksforgeeks geeks for geeks"