Advertisement
Spocoman

04. Short Words

Jan 26th, 2024
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <set>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     string line, word;
  10.     getline(cin, line);
  11.  
  12.     istringstream ss(line);
  13.  
  14.     set<string> words;
  15.  
  16.     while (ss >> word) {
  17.         if (word.size() < 5) {
  18.             for (int i = 0; i < word.size(); i++) {
  19.                 word[i] = tolower(word[i]);
  20.             }
  21.             words.insert(word);
  22.         }
  23.     }
  24.  
  25.     while (!words.empty()) {
  26.         cout << *words.begin();
  27.         words.erase(words.begin());
  28.         if (!words.empty()) {
  29.             cout << ", ";
  30.         }
  31.     }
  32.  
  33.     cout << endl;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement