Guest User

Untitled

a guest
Apr 11th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream> // iostream is for cout and endl; not necessary just to use vector or string
  3. #include <vector>
  4. #include <string>
  5. #include <sstream>
  6. #include <algorithm>
  7. #include <iterator>
  8.  
  9. using namespace std;
  10.  
  11. std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
  12.         std::stringstream ss(s);
  13.         std::string item;
  14.         while (std::getline(ss, item, delim)) {
  15.                 elems.push_back(item);
  16.         }
  17.         return elems;
  18. }
  19.  
  20. int _tmain(int argc, _TCHAR* argv[])
  21. {
  22.         string sentence;
  23.         vector<string> words;
  24.  
  25.         std::getline(cin, sentence);
  26.  
  27.         words = split(sentence, ' ', words);
  28.  
  29.         sort(words.begin(), words.end());
  30.  
  31.         for (auto &word : words){ cout << word << endl; };
  32.  
  33.         return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment