Advertisement
chevengur

Вводный курс: основы C++ | Урок 5: Хитрости константных ссылок 2/2

Sep 1st, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. vector<string> SplitIntoWords(const string& text) {
  8.     vector<string> words;
  9.     string word;
  10.     for (const char c : text) {
  11.         if (c == ' ') {
  12.             if (!word.empty()) {
  13.                 words.push_back(word);
  14.                 word.clear();
  15.             }
  16.         } else {
  17.             word += c;
  18.         }
  19.     }
  20.     if (!word.empty()) {
  21.         words.push_back(word);
  22.     }
  23.  
  24.     return words;
  25. }
  26.  
  27. string ReadSearchQuery(){
  28.     string query;
  29.     getline(cin,query);
  30.     return query;
  31. }
  32.  
  33. int main() {
  34.     for(string i: SplitIntoWords(ReadSearchQuery()))
  35.         cout << "[" << i << "]" << " ";
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement