Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string norm(const string& s) {
  5.   string aux;
  6.   for (char c : s)
  7.     if (isalnum(c)) aux += tolower(c);
  8.     else if (isspace(c)) {
  9.       if (!aux.size() || !isspace(aux.back())) aux += c;
  10.     }
  11.  
  12.   string ans;
  13.   for (int i = 0; i < aux.size();) {
  14.     while (i < aux.size() && isspace(aux[i])) ans += aux[i], ++i;
  15.     string word;
  16.     while (i < aux.size() && isalnum(aux[i])) word += aux[i], ++i;
  17.     if (word.size() > 3) ans += word;
  18.   }
  19.   if (ans.size() && isspace(ans[0])) ans = ans.substr(1);  // it is not clear from the statement if this line should exist or not.
  20.   return ans;
  21. }
  22.  
  23. int main() {
  24.   string s;
  25.   getline(cin, s);
  26.  
  27.   cout << norm(s);
  28.  
  29.   return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement