Skip to content

Instantly share code, notes, and snippets.

@ShaderManager
Created March 3, 2015 07:54
Show Gist options
  • Save ShaderManager/9d6bc4250fa8d52d7830 to your computer and use it in GitHub Desktop.
Save ShaderManager/9d6bc4250fa8d52d7830 to your computer and use it in GitHub Desktop.
bool check(const std::string& s, const std::vector<std::string>& d)
{
auto ts = s;
while (true)
{
auto match = std::make_pair(ts.npos, 0);
for (auto&& w : d)
{
auto pos = ts.find(w);
if (pos != ts.npos && w.length() > match.second)
{
match = std::make_pair(pos, w.length());
}
}
if (match.first == ts.npos)
break;
ts.erase(match.first, match.second);
ts.insert(match.first, "\1");
}
for (auto c : ts)
{
if (c != '\1')
{
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment