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;
- }
Comments
-
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string query;
- getline(cin, query);
- int i;
- string word;
- for(i = 0; i < query.size(); i++){
- if(query[i] != ' '){
- word += query[i];
- }
- else{
- cout << "["s << word << "]"s << endl;
- word = ""s;
- }
- }
- cout << "["s << word << "]"s << endl;
- }
-
- #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 << "["s << word << "]"s << endl;
- word = ""s;
- }else{
- word += query[i];
- }
- }
- cout << "["s << word << "]"s << endl;
- }
-
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string query;
- getline(cin, query);
- query += " "s;
- string output_data = ""s;
- for (int i = 0; i <= query.size(); ++i) {
- if (query[i] != ' ') {
- output_data += query[i];
- }
- else{
- cout<< "["s + output_data + "]"s <<endl;
- output_data = ""s;
- }
- }
- }
-
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string query , str ="["s;
- getline(cin, query);
- for(int i = 0 ; i <= query.size()-1; i++){
- if (query[i] == ' '){
- str+= "]\n["s;
- }else{
- str+= query[i];
- }
- }
- cout <<str +"]"<<endl;
- }
-
- // с использованием цикла while
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string query, word;
- getline(cin, query);
- int i = 0;
- int s = query.size();
- while (i <= s){
- if ((query[i] != ' ') && (i != s)){
- word += query[i];
- } else {
- cout << "["s << word << "]"s << endl;
- word = ""s;
- }
- ++i;
- }
- }
-
- #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] != ' ' && i < query.size()) {
- word += query[i];
- } else {
- cout << "[" << word << "]" << endl;
- word = "";
- }
- }
- }
-
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string query;
- getline(cin, query);
- cout << "[";
- string word;
- for (int i = 0; i < query.size(); ++i)
- {
- word = query[i];
- if (word != " ")
- {
- cout << word;
- } else
- {
- cout << "]" << endl << "[";
- }
- }
- cout << "]";
- return 0;
- }
Add Comment
Please, Sign In to add comment