#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
auto fn_Tokenize = [](const std::string& vrx_String, const char vc_Delimeter) -> std::vector<std::string>
{
std::vector<std::string> x_Result;
size_t x_StartOfCurrentSubstring = 0;
size_t x_CurrentDelimeterPos = 0;
// First find not delimeter character after last found delimeter position
for(;;)
{
x_CurrentDelimeterPos = vrx_String.find_first_of(vc_Delimeter, x_CurrentDelimeterPos);
if (x_CurrentDelimeterPos != std::string::npos)
{
x_Result.push_back(vrx_String.substr(x_StartOfCurrentSubstring, x_CurrentDelimeterPos - x_StartOfCurrentSubstring));
++x_CurrentDelimeterPos;
x_StartOfCurrentSubstring = x_CurrentDelimeterPos;
}
else
{
x_Result.push_back(vrx_String.substr(x_StartOfCurrentSubstring));
break;
}
}
return x_Result;
};
std::vector<std::string> result = fn_Tokenize("A;B;;;C;DEF", ';');
for (std::string a : result)
{
std::cout << a << std::endl;
}
// your code goes here
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBhdXRvIGZuX1Rva2VuaXplID0gW10oY29uc3Qgc3RkOjpzdHJpbmcmIHZyeF9TdHJpbmcsIGNvbnN0IGNoYXIgdmNfRGVsaW1ldGVyKSAtPiBzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4KICAgIHsKICAgICAgICBzdGQ6OnZlY3RvcjxzdGQ6OnN0cmluZz4geF9SZXN1bHQ7CiAgICAgICAgc2l6ZV90IHhfU3RhcnRPZkN1cnJlbnRTdWJzdHJpbmcgPSAwOwogICAgICAgIHNpemVfdCB4X0N1cnJlbnREZWxpbWV0ZXJQb3MgICA9IDA7CgogICAgICAgIC8vIEZpcnN0IGZpbmQgbm90IGRlbGltZXRlciBjaGFyYWN0ZXIgYWZ0ZXIgbGFzdCBmb3VuZCBkZWxpbWV0ZXIgcG9zaXR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