fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main ()
  5. {
  6. string str, str1, str2;
  7. int i=0, SecondStringSize = 0;
  8. getline(cin, str);
  9. getline(cin, str1);
  10. getline(cin, str2);
  11. cout << "str is ";
  12. for(auto c : str)
  13. cout << "\'" << c << "\'" << ", ";
  14. cout << endl;
  15.  
  16. cout << "str1 is ";
  17. for(auto c : str1)
  18. cout << "\'" << c << "\'" << ", ";
  19. cout << endl;
  20.  
  21. cout << "str2 is ";
  22. for(auto c : str2)
  23. cout << "\'" << c << "\'" << ", ";
  24. cout << endl;
  25. SecondStringSize = str1.size();
  26. cout << "изначально SSS = " << SecondStringSize << endl;
  27. while (SecondStringSize != string::npos)
  28. {
  29. i++;
  30. str.replace(SecondStringSize, str1.size(), str2);
  31. cout << "После " << i << " замены str = " << str << endl;
  32. SecondStringSize = str.find(str1, SecondStringSize);
  33. cout << "a SSS = " << SecondStringSize << endl << endl;
  34. }
  35. cout << "Ответ " <<str<<endl;
  36. return 0;
  37. }
Success #stdin #stdout 0s 3464KB
stdin
aabb
cc
d
stdout
str is 'a', 'a', 'b', 'b', 
str1 is 'c', 'c', 
str2 is 'd', 
изначально SSS = 2
После 1 замены str = aad
a SSS = -1

Ответ aad