Serby__

c39III

May 4th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. char a;
  6. char b;
  7.  
  8. void solve(string & s, int pos)
  9. {
  10.     if (s[pos] == a)
  11.     {
  12.         string t1 = s.substr(0, pos + 1);
  13.         string t2 = s.substr(pos + 1, s.length() - pos + 1);
  14.         s = t1 + b + t2;
  15.         pos++;
  16.     }
  17.    
  18.     if (pos + 1 != s.length())
  19.         solve(s, pos + 1);
  20.  
  21. }
  22. int main()
  23. {
  24.     cin >> a >> b;
  25.     string s;
  26.     cin >> s;
  27.     solve(s, 0);
  28.     cout << s;
  29. }
Add Comment
Please, Sign In to add comment