mstoyanov7

4 zad

Apr 21st, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. std::string readInput() {
  5. std::string line;
  6. getline(std::cin, line);
  7. return line;
  8. }
  9.  
  10. void replaceWords(std::string& sentence, std::string findWord, std::string replaceWord) {
  11.  
  12.  
  13. size_t pos;
  14. size_t len = findWord.length();
  15.  
  16. while ((pos = sentence.find(findWord)) != std::string::npos) {
  17. sentence.replace(pos, len, replaceWord);
  18. }
  19. }
  20.  
  21.  
  22. int main() {
  23.  
  24. std::string sentence = readInput();
  25. std::string findWord = readInput();
  26. std::string replaceWord = readInput();
  27.  
  28. replaceWords(sentence, findWord, replaceWord);
  29.  
  30. std::cout << sentence;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment