Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string GetNormalizedString() const {
- auto vector = std::vector<std::string>();
- int j = -1;
- for (size_t i = 0; i < name_.length(); ++i) {
- if (!isalpha(name_[i])) {
- if (static_cast<int>(i) != j + 1) {
- vector.push_back(name_.substr(j + 1, i - j - 1));
- }
- j = i;
- }
- }
- if (j + 1 != static_cast<int>(name_.length())) {
- vector.push_back(name_.substr(j + 1, name_.length() - j));
- }
- for (auto& elem : vector) {
- for (auto& ch : elem) {
- ch = tolower(ch);
- }
- }
- std::sort(vector.begin(), vector.end());
- std::string res = "";
- for (const auto& elem : vector) {
- res += elem;
- res += " ";
- }
- return res.back() == ' ' ? res.substr(0, res.length() - 1) : res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement