Advertisement
Lavig

Другий семестр. Лабораторна робота №3 (Завдання 3)

Feb 18th, 2025
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     SetConsoleOutputCP(1251);
  11.     SetConsoleCP(1251);
  12.     string text{}, temp_word{};
  13.     vector<string> all_words;
  14.     string word;
  15.     int i{};
  16.     cout << "Введіть будь-який текст: " << endl;
  17.     getline(cin, text);
  18.     for (i = 0; i < text.size(); i++) {
  19.         if (text[i] != ' ') {
  20.             word += text[i];
  21.         }
  22.         else {
  23.             all_words.push_back(word);
  24.             word = "";
  25.         }
  26.     }
  27.     all_words.push_back(word);
  28.     cout << "Список слів в наведеному тексті: " << endl;
  29.     for (i = 0; i < all_words.size(); i++) {
  30.         if (all_words[i] != "") {
  31.             cout << all_words[i] << endl;
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement