Ad
  • Custom User Avatar

    Why you need to decrease the "unit" in the loop?

    while( result.length() % unit != 0 ) unit /= 3;

    I suggest replacing "regex_search" with "sregex_iterator":

    	regex reg("1+|0+");
    	int unit = INT_MAX;
    	for (std::sregex_iterator it(text.begin(), text.end(), reg), end; it != end; ++it)
    	{
    		const auto length = (*it)[0].length();
    		if (length < unit)
    			unit = length;
    	}