Advertisement
cska1312

04. Short Words

May 11th, 2023
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <utility>
  4. #include <sstream>
  5. #include <set>
  6. using namespace std;
  7.  
  8. string &lower_str(string &str)
  9. {
  10. for( string::iterator i = str.begin(); i != str.end(); i++)
  11. *i = tolower(*i);
  12.  
  13. return str;
  14. }
  15.  
  16. int main()
  17. {
  18.  string str;
  19. getline(cin, str);
  20. istringstream istr(lower_str(str));
  21.  
  22. string word;
  23. set<string> words;
  24.  
  25. while(istr >> word)
  26. words.insert(word);
  27.  
  28. bool first = true;
  29.  
  30. for(set<string>::iterator i = words.begin(); i != words.end(); i++)
  31. {
  32. if(i->length() < 5)
  33. {
  34. if(first)
  35. first = false;
  36. else
  37. cout << ", ";
  38.  
  39. cout << *i;
  40. }
  41. }
  42. cout << endl;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement