#include<iostream>
#include<string>
using namespace std;

string findReplace(string str,string find,string replace){
    int pos=0;
    while(true){
        pos = str.find(find);
        if (pos == -1) break;
        str.replace(pos, find.length(),replace );
        
    }
    return str;
}

string findErase(string str,string find){
    int pos=0;
    while(true){
        pos = str.find(find);
        if (pos == -1) break; 
        str.erase(pos, find.length());
    }
    return str;
}


int main(){
string str,find,replace,erase;
cout<<"enter the string: ";
getline(cin,str);
cout<<"enter the word you want to find: ";
getline(cin,find);
cout<<"do you wish to erase it or to replace it?(erase,replace)";
string wish;
getline(cin,wish);
if(wish=="erase"||wish=="Erase"){
    str = findErase(str, find);
    
    cout << "result: " << str << endl;
}
else if(wish=="replace"||wish=="Replace"){
cout<<"enter the replace: ";
getline(cin,replace);
    str = findReplace(str, find, replace);
    
    cout << "result: " << str << endl;
}
else{
    cout<<"invalid input"<<endl;
    cout<<"the valid words are:(erase , Erase , replace , Replace)";
}
return 0;
}