Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. std::string GetNormalizedString() const {
  2.         auto vector = std::vector<std::string>();
  3.         int j = -1;
  4.         for (size_t i = 0; i < name_.length(); ++i) {
  5.             if (!isalpha(name_[i])) {
  6.                 if (static_cast<int>(i) != j + 1) {
  7.                     vector.push_back(name_.substr(j + 1, i - j - 1));
  8.                 }
  9.                 j = i;
  10.             }
  11.         }
  12.         if (j + 1 != static_cast<int>(name_.length())) {
  13.             vector.push_back(name_.substr(j + 1, name_.length() - j));
  14.         }
  15.         for (auto& elem : vector) {
  16.             for (auto& ch : elem) {
  17.                 ch = tolower(ch);
  18.             }
  19.         }
  20.         std::sort(vector.begin(), vector.end());
  21.         std::string res = "";
  22.         for (const auto& elem : vector) {
  23.             res += elem;
  24.             res += " ";
  25.         }
  26.         return res.back() == ' ' ? res.substr(0, res.length() - 1) : res;
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement