-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReplace_Word.cpp
37 lines (34 loc) · 979 Bytes
/
Replace_Word.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// #include <iostream>
// using namespace std;
// main()
// {
// int index;
// string my_str = "Hello...Here all Hello will be replaced";
// string sub_str = "ABCDE";
// cout << "Initial String :" << my_str << endl;
// // replace all Hello with welcome
// while ((index = my_str.find("Hello")) != string::npos)
// { // for each location where Hello is found
// my_str.replace(index, sub_str.length(), sub_str); // remove and replace from that position
// }
// cout << "Final String :" << my_str;
// }
#include <bits/stdc++.h>
using namespace std;
int main()
{
int testcase;
cin >> testcase;
while (testcase--)
{
string s, x;
cin >> s >> x;
int cnt = 0;
while ((cnt = s.find(x)) != -1)
{
s.replace(cnt, x.size(), "#");
}
cout << s << endl;
}
return 0;
}