Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp: определяет точку входа для консольного приложения.
- //
- #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;
- int _tmain(int argc, _TCHAR* argv[])
- {
- string sentence;
- // получаем строку из консоли
- std::getline(cin, sentence);
- // делим предложение на слова по пробелу
- istringstream iss(sentence);
- copy(istream_iterator<string>(iss),
- istream_iterator<string>(),
- ostream_iterator<string>(cout, "\n"));
- // складываем слова в вектор
- vector<string> words{ istream_iterator < string > {iss},
- istream_iterator < string > {} };
- // сортируем вектор
- sort(words.begin(), words.end());
- // выводим в консоль
- for (auto &word : words){ cout << word << endl; };
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment