-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplit.cpp
More file actions
47 lines (39 loc) · 775 Bytes
/
Split.cpp
File metadata and controls
47 lines (39 loc) · 775 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
// Split String, O(n)
vector<string> split(const string &s, const char ch = ' ') {
int n = s.size();
vector<string> sp;
string tmp;
for (int i = 0; i < n; i++) {
if (s[i] != ch) {
tmp += s[i];
}
else if (tmp != "") {
sp.push_back(tmp);
tmp = "";
}
}
if (tmp != "") {
sp.push_back(tmp);
}
return sp;
}
void solve() {
string s;
getline(cin, s);
vector<string> sp = split(s);
for (auto str : sp) {
cout << str << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}