Guest User

Untitled

a guest
May 21st, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. using namespace std;
  5. int main()
  6. {
  7. string s = "Today was hot and I had a hot tea";
  8. string xold = "hot";
  9. string xnew = "cold";
  10. int strsub( string s, string xold, string xnew );
  11. cout << strsub( s, xold, xnew ) << endl;
  12. return ( 0 );
  13. }
  14.  
  15. string strsub( string s, string xold, string xnew )
  16. {
  17. string sum = "";
  18. bool isqualified = 0;
  19. for( int i = 0; i < s.size(); )
  20. {
  21. if( s.substr( i, xold.size() ) == xold )
  22. {
  23. if( isqualified == 0 )
  24. {
  25. i += xnew.size();
  26. sum += xnew;
  27. isqualified = 1;
  28. cout << sum << endl;
  29. }
  30. }
  31. else
  32. {
  33. sum += s[i];
  34. i += 1;
  35. cout << sum << endl;
  36. }
  37. }
  38. return( sum );
Add Comment
Please, Sign In to add comment