Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string query;
- getline(cin, query);
- string word;
- for (int i = 0; i < query.size(); ++i)
- {
- if (query[i] == ' ')
- {
- cout << '[' << word << ']' << endl;
- word = ""s;
- }
- else
- {
- word += query[i];
- }
- }
- cout << '[' << word << ']' << endl;
- }
- ********************************************************************
- мой
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <vector>
- using namespace std;
- int main() {
- string query;
- getline(cin, query);
- vector<string> words;
- string word;
- for (int i = 0; i != query.size(); ++i)
- {
- if (query[i] != ' ')
- {
- if (word.empty())
- {
- word.push_back('[');
- word.push_back(query[i]);
- }
- else
- {
- word.push_back(query[i]);
- }
- }
- else
- {
- word.push_back(']');
- cout << word << endl;
- word.clear();
- }
- }
- word.push_back(']');
- cout << word << endl;
- word.clear();
- // выведите все индексы символов, следующие за словами
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement