Advertisement
Gistrec

Разбиение на слова

Dec 30th, 2018
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. vector<string> SplitIntoWords(const string& s) {
  9.     vector<string> result;
  10.     std::istringstream iss(s);
  11.  
  12.     string pice;
  13.     while (std::getline(iss, pice, ' ')) {
  14.         result.push_back(pice);
  15.     }
  16.     return result;
  17. }
  18.  
  19. int main() {
  20.     string s = "C Cpp Java Python";
  21.  
  22.     vector<string> words = SplitIntoWords(s);
  23.     cout << words.size() << " ";
  24.     for (auto it = begin(words); it != end(words); ++it) {
  25.         if (it != begin(words)) {
  26.             cout << "/";
  27.         }
  28.         cout << *it;
  29.     }
  30.     cout << endl;
  31.  
  32.     system("pause");
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement