Skip to content

Instantly share code, notes, and snippets.

@rusdevops
Last active March 24, 2021 17:53
Show Gist options
  • Save rusdevops/bd5589a0f550c5766109705450667537 to your computer and use it in GitHub Desktop.
Save rusdevops/bd5589a0f550c5766109705450667537 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
std::string& normalize(std::string& s, const char c = '_') {
auto j = s.begin();
for (auto i = s.begin(); i != s.end(); ++i) {
if (*i != c || (j != s.begin() && *(j - 1) != c))
*j++ = std::move(*i);
}
s.erase(j, s.end());
if (!s.empty() && s.back() == c)
s.pop_back();
return s;
}
int main() {
std::string s;
std::cin >> s;
std::cout << normalize(s);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment