Created
September 12, 2018 08:17
-
-
Save mochow13/9374e624eafd4b034ae8ff1f8a88227a 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
std::string mirror_ends(const std::string& in) | |
{ | |
// mismatch takes two ranges as input, (first1,last1,first2,last2) | |
// if last2 is not given, it considers first2+(last1-first1) as last2 | |
return std::string(in.begin(), std::mismatch(in.begin(), in.end(), in.rbegin()).first); | |
} | |
int main() | |
{ | |
std::cout << mirror_ends("abXYZba") << '\n' | |
<< mirror_ends("abca") << '\n' | |
<< mirror_ends("aba") << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment