Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
1.4 kB
12
Indexable
Never
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    string* sites = new string[n];
    for (int i = 0; i < n; i++) {
        cin >> sites[i];
    }
    
    string word = "";
    string site = "";
    
    string myWord = "";
    
    while (true) {
        cin >> word;
        if (word == "STOP") break;
        cin >> site;
        
        if (site == "bg-mama.bg" || site == "planeta.bg" || site == "moodle.com") continue;
        
        bool isSiteOpened = false;
        for (int i = 0; i < n; i++) {
            if (sites[i] == site) {
                isSiteOpened = true;
                break;
            }
        }
        
        if (isSiteOpened) {
            myWord.append(word);
            myWord.append(" ");
        }
    }
    
    myWord.pop_back();
    
    string command, arg1, arg2, arg3;
    while (true) {
        cin >> command;
        if (command == "STOP") break;
        if (command == "REPLACE") {
            cin >> arg1 >> arg2;
            int pos = myWord.find(arg1);
            myWord.replace(pos, arg1.length(), arg2);
        }
        
        if (command == "REMOVE") {
            cin >> arg3;
            int pos = myWord.find(arg3);
            myWord.replace(pos, arg3.length(), "");
        }
    }
    
    cout << myWord << endl;
    
    delete[] sites;
    sites = nullptr;
    
    return 0;
}
Leave a Comment