Guest User

Untitled

a guest
Apr 11th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. // ConsoleApplication2.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4.  
  5. #include "stdafx.h"
  6. #include <iostream> // iostream is for cout and endl; not necessary just to use vector or string
  7. #include <vector>
  8. #include <string>
  9. #include <sstream>
  10. #include <algorithm>
  11. #include <iterator>
  12.  
  13. using namespace std;
  14.  
  15. int _tmain(int argc, _TCHAR* argv[])
  16. {
  17.     string sentence;
  18.  
  19.     // получаем строку из консоли
  20.     std::getline(cin, sentence);
  21.  
  22.     // делим предложение на слова по пробелу
  23.     istringstream iss(sentence);
  24.     copy(istream_iterator<string>(iss),
  25.         istream_iterator<string>(),
  26.         ostream_iterator<string>(cout, "\n"));
  27.  
  28.     // складываем слова в вектор
  29.     vector<string> words{ istream_iterator < string > {iss},
  30.         istream_iterator < string > {} };
  31.  
  32.     // сортируем вектор
  33.     sort(words.begin(), words.end());
  34.  
  35.     // выводим в консоль
  36.     for (auto &word : words){ cout << word << endl; };
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment