Advertisement
BojidarDosev

Untitled

Jun 13th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <string>
  7. #include <set>
  8.  
  9. using namespace std;
  10.  
  11.  
  12. int main() {
  13. int constraints;
  14. cin >> constraints;
  15. cin.ignore();
  16.  
  17. set<string> open_tabs;
  18. for (int i = 0; i < constraints; i++)
  19. {
  20. string tab;
  21. getline(cin, tab);
  22. open_tabs.insert(tab);
  23. }
  24.  
  25. set<string> untrusted_sites = { "bg-mama.bg", "planeta.bg", "moodle.bg" };
  26.  
  27. string album_title;
  28.  
  29. while (true)
  30. {
  31. string word, web;
  32. cin >> word;
  33. if (word == "STOP") break;
  34. cin >> web;
  35.  
  36. if (open_tabs.count(web) && !untrusted_sites.count(web))
  37. {
  38. if (!album_title.empty())
  39. {
  40. album_title += " ";
  41. }
  42. album_title += word;
  43. }
  44. }
  45.  
  46. cin.ignore();
  47.  
  48. while (true)
  49. {
  50. string action;
  51. cin >> action;
  52.  
  53. if (action == "STOP") break;
  54.  
  55. if (action == "REPLACE")
  56. {
  57. string old_text, result;
  58. cin >> old_text >> result;
  59. size_t pos = 0;
  60. while ((pos = album_title.find(old_text, pos)) != string::npos)
  61. {
  62. album_title.replace(pos, old_text.length(), result);
  63. pos += result.length();
  64. }
  65. }
  66. else if (action == "REMOVE")
  67. {
  68. string text_to_remove;
  69. cin >> text_to_remove;
  70. size_t pos = album_title.find(text_to_remove);
  71. if (pos != string::npos)
  72. {
  73. album_title.erase(pos, text_to_remove.length());
  74. }
  75. }
  76.  
  77. cin.ignore();
  78. }
  79.  
  80. cout << album_title << endl;
  81.  
  82. return 0;
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement