I'm solving the challenge on Reddit here
And I can't find out how to replace a specific text of a string with another one. I managed to find out how to check if that specific text exists, but I'm having problems replacing it with another text or completely removing it from the string (as the challenge requires that).
Here's my code so far:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int law (string a);
int main() {
string a;
cin >> a;
cout << law(a) << endl;
return 0;
}
int law(string a){
if (a.find("NOT") != string::npos)
return a.replace(a.begin(), a.end(), ' ');
if(a.find("NOT") != string::npos && ((a.find("AND") == string::npos) || (a.find("OR") == string::npos)))
return a.erase(remove(a.begin(), a.end(), "NOT"), a.end());
}