ppl this should work ! complexity would be number of "post" - delimiter in this case, in the string . let me know if you people have better run time then this
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
void split(const string& str, const string& delimiter = "post") {
vector <string> tokens;
string::size_type lastPos = 0;
string::size_type pos = str.find(delimiter, lastPos);
while (string::npos != pos) {
// Found a token, add it to the vector.
cout << str.substr(lastPos, pos - lastPos) << endl;
//tokens.push_back(str.substr(lastPos+4, pos - lastPos));
lastPos = pos + delimiter.size();
pos = str.find(delimiter, lastPos);
}
}
int main() {
split("wat post but post get post roast post");
}