fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <list>
  4.  
  5. using namespace std;
  6.  
  7. list<string> createCodeList()
  8. {
  9. list<string> codeList;
  10. string input;
  11.  
  12. cout << "Enter your coded text: " << endl;
  13. getline(cin, input);
  14.  
  15. string::size_type start = 0, end;
  16. while ((end = input.find("pe", start)) != string::npos)
  17. {
  18. codeList.push_back(input.substr(start, end-start));
  19. codeList.push_back("pe");
  20. start = end + 2;
  21. }
  22. if (start < input.size())
  23. codeList.push_back(input.substr(start));
  24.  
  25. return codeList;
  26. }
  27.  
  28. void removeCodeWords(list<string>& codeList)
  29. {
  30. for (auto it = codeList.begin(); it != codeList.end(); )
  31. {
  32. if (*it == "pe")
  33. {
  34. it = codeList.erase(it);
  35. }
  36. else
  37. {
  38. ++it;
  39. }
  40. }
  41. }
  42.  
  43. void printCodeList(const list<string>& codeList)
  44. {
  45. for (const string& code : codeList)
  46. {
  47. cout << code;
  48. }
  49. cout << endl;
  50. }
  51.  
  52. int main()
  53. {
  54. list<string> codeList = createCodeList();
  55. removeCodeWords(codeList);
  56. printCodeList(codeList);
  57. return 0;
  58. }
Success #stdin #stdout 0.01s 5552KB
stdin
Hepello Ipe hapeve ape prpeobpelepem
stdout
Enter your coded text: 
Hello I have a problem