#include <iostream>
#include <string>
#include <vector>
using namespace std; // я ленивый, да
void split(const string& source, const string& delimiters, vector<string>& result)
{
// поддерживаем следующий инвариант: символ по индексу есть начало нового куска
// пропускаем разделители в начале
auto start = source.find_first_not_of(delimiters);
while (start != string::npos)
{
// ищем следующий конец куска
auto end = source.find_first_of(delimiters, start);
// и его длину
auto len = end == string::npos ? string::npos : (end - start);
// запоминаем найденный кусок
result.push_back(source.substr(start, len));
// и переходим к следующему
start = source.find_first_not_of(delimiters, end);
}
}
int main()
{
vector<string> result;
split("'twas brillig, and the slithy toves did gyre and gimble in the wabe!",
"' !,\t",
result);
split("all mimsy were the borogoves",
"' !,\t",
result);
for (auto& r : result)
cout << r << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsgLy8g0Y8g0LvQtdC90LjQstGL0LksINC00LAKCnZvaWQgc3BsaXQoY29uc3Qgc3RyaW5nJiBzb3VyY2UsIGNvbnN0IHN0cmluZyYgZGVsaW1pdGVycywgdmVjdG9yPHN0cmluZz4mIHJlc3VsdCkKewogICAgLy8g0L/QvtC00LTQtdGA0LbQuNCy0LDQtdC8INGB0LvQtdC00YPRjtGJ0LjQuSDQuNC90LLQsNGA0LjQsNC90YI6INGB0LjQvNCy0L7QuyDQv9C+INC40L3QtNC10LrRgdGDINC10YHRgtGMINC90LDRh9Cw0LvQviDQvdC+0LLQvtCz0L4g0LrRg9GB0LrQsAogICAgLy8g0L/RgNC+0L/Rg9GB0LrQsNC10Lwg0YDQsNC30LTQtdC70LjRgtC10LvQuCDQsiDQvdCw0YfQsNC70LUKICAgIGF1dG8gc3RhcnQgPSBzb3VyY2UuZmluZF9maXJzdF9ub3Rfb2YoZGVsaW1pdGVycyk7CiAgICB3aGlsZSAoc3RhcnQgIT0gc3RyaW5nOjpucG9zKQogICAgewogICAgICAgIC8vINC40YnQtdC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