Skip to content

Instantly share code, notes, and snippets.

@liancheng
Last active December 18, 2015 13:18
Show Gist options
  • Save liancheng/5788608 to your computer and use it in GitHub Desktop.
Save liancheng/5788608 to your computer and use it in GitHub Desktop.
string reverseSentence (string const& s)
{
string t (s.rbegin (), s.rend ());
for (auto p = begin (t), q = begin (t); p != end (t); ) {
p = find_if (p, end (t), [] (char c) { return c != ' '; });
q = find (p, end (t), ' ');
reverse (p, q);
p = q;
}
return move (t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment