Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream> // iostream is for cout and endl; not necessary just to use vector or string
- #include <vector>
- #include <string>
- #include <sstream>
- #include <algorithm>
- #include <iterator>
- using namespace std;
- std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
- std::stringstream ss(s);
- std::string item;
- while (std::getline(ss, item, delim)) {
- elems.push_back(item);
- }
- return elems;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- string sentence;
- vector<string> words;
- std::getline(cin, sentence);
- words = split(sentence, ' ', words);
- sort(words.begin(), words.end());
- for (auto &word : words){ cout << word << endl; };
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment