Advertisement
allia

меняю местами слова

Sep 19th, 2020
1,138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <sstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.   string a, b, c;
  11.   int n=0, m=0, z=0, s1=0, s2=0;
  12.   getline (cin, a);
  13.   getline (cin, b);
  14.   getline (cin, c);
  15.  
  16.   n=a.size();
  17.   m=b.size();
  18.   z=c.size();
  19.  
  20.  s1 = a.find(b);
  21.  s2 = a.find(c);
  22.  
  23. if (s1<s2)
  24.  {
  25.    a.erase(s1, m);
  26.    a.insert(s1, c);
  27.    a.erase(s2+z-m, z);
  28.    a.insert(s2+z-m, b);
  29.  }
  30. else
  31.  {
  32.    a.erase(s2, z);
  33.    a.insert(s2, b);
  34.    a.erase(s1+m-z, m);
  35.    a.insert(s1+m-z, c);
  36.  }
  37.  cout << a;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement