Last active
March 24, 2021 17:53
-
-
Save rusdevops/bd5589a0f550c5766109705450667537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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