Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- char a;
- char b;
- void solve(string & s, int pos)
- {
- if (s[pos] == a)
- {
- string t1 = s.substr(0, pos + 1);
- string t2 = s.substr(pos + 1, s.length() - pos + 1);
- s = t1 + b + t2;
- pos++;
- }
- if (pos + 1 != s.length())
- solve(s, pos + 1);
- }
- int main()
- {
- cin >> a >> b;
- string s;
- cin >> s;
- solve(s, 0);
- cout << s;
- }
Add Comment
Please, Sign In to add comment