-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_demiliter.cpp
49 lines (36 loc) · 941 Bytes
/
string_demiliter.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <sstream>
#include <vector>
#include <iostream>
using namespace std;
vector<int> parseInts(string str, string delimiter) {
// Complete this function
string del = delimiter;
int start = 0;
int end = str.find(del);
string sk;
int num;
vector<int> int_arr;
while (end != -1) {
sk = str.substr(start, end - start);
num = stoi(sk);
int_arr.push_back(num);
// cout << str.substr(start, end - start) << endl;
start = end + del.size();
end = str.find(del, start);
}
sk = str.substr(start, end - start);
num = stoi(sk);
int_arr.push_back(num);
return int_arr;
}
int main() {
string str;
getline(cin, str);
string delimiter;
getline(cin, delimiter);
vector<int> integers = parseInts(str, delimiter);
for(int i = 0; i < integers.size(); i++) {
cout << integers[i] << "\n";
}
return 0;
}