fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <iterator>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <string>
  7. #include <cctype>
  8.  
  9.  
  10. void in(std::string & text);
  11. void split(std::string text, std::vector<std::string> & words);
  12. void sort(std::vector<std::string> & words);
  13. void out(std::vector<std::string> const& words);
  14.  
  15.  
  16. int main() {
  17. std::string text;
  18. std::vector<std::string> words;
  19.  
  20. in(text);
  21. split(text, words);
  22. sort(words);
  23. out(words);
  24. }
  25.  
  26.  
  27. void in(std::string & text) {
  28. text.assign(
  29. (std::istreambuf_iterator<std::string::value_type>(std::cin)),
  30. std::istreambuf_iterator<std::string::value_type>());
  31. }
  32.  
  33. void split(std::string text, std::vector<std::string> & words) {
  34. std::replace_if(text.begin(), text.end(), ::ispunct, ' ');
  35. std::istringstream iss(text);
  36. words.assign(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>());
  37. }
  38.  
  39. void sort(std::vector<std::string> & words) {
  40. std::sort(words.begin(), words.end());
  41. }
  42.  
  43. void out(std::vector<std::string> const& words) {
  44. std::copy(words.begin(), words.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
  45. }
  46.  
Success #stdin #stdout 0s 3080KB
stdin
What,the, heck
   is,going,
 , on?
stdout
What
going
heck
is
on
the