Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- string norm(const string& s) {
- string aux;
- for (char c : s)
- if (isalnum(c)) aux += tolower(c);
- else if (isspace(c)) {
- if (!aux.size() || !isspace(aux.back())) aux += c;
- }
- string ans;
- for (int i = 0; i < aux.size();) {
- while (i < aux.size() && isspace(aux[i])) ans += aux[i], ++i;
- string word;
- while (i < aux.size() && isalnum(aux[i])) word += aux[i], ++i;
- if (word.size() > 3) ans += word;
- }
- if (ans.size() && isspace(ans[0])) ans = ans.substr(1); // it is not clear from the statement if this line should exist or not.
- return ans;
- }
- int main() {
- string s;
- getline(cin, s);
- cout << norm(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement