Untitled
unknown
plain_text
4 years ago
622 B
7
Indexable
#include <iostream> #include <string> #include <vector> using namespace std; vector<string> SplitIntoWords(string text) { vector<string> words; string word; for (int i = 0; i < text.size(); ++i) { if (text[i] == ' ') { words.push_back(word); word = ""; } else { word += text[i]; } } words.push_back(word); return words; } int main() { string query; getline(cin, query); for (string word : SplitIntoWords(query)) { cout << '[' << word << ']' << endl; } return 0; }
Editor is loading...