CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// vector.push_back(str.split()) (by HonFu)
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
vector<string> v{};
string s{}, dummy{};
getline(cin, s);
cout << s << endl;
for (int i=0; i<s.length(); ++i) {
if(s.at(i) == ' ') {
v.push_back(dummy);
dummy.clear();
while(i<s.length()
&& s.at(i) == ' ')
++i;
--i;
} else dummy += s.at(i);
}
v.push_back(dummy);
for(string el: v) cout << el << ' ';
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run