-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_stream.cpp
More file actions
34 lines (27 loc) · 1.09 KB
/
string_stream.cpp
File metadata and controls
34 lines (27 loc) · 1.09 KB
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
/*
Prompt: https://hackerrank-challenge-pdfs.s3.amazonaws.com/8045-c-tutorial-stringstream-English?response-content-disposition=inline%3B%20filename%3Dc-tutorial-stringstream-English.pdf&response-content-type=application%2Fpdf&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAR6O7GJNX5DNFO3PV%2F20250616%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250616T163706Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=d569351e6bf96f180593da175647b79625281409e760572227a255185aa28edc
Submission: https://www.hackerrank.com/challenges/c-tutorial-stringstream/submissions/code/436132845
*/
#include <sstream>
#include <vector>
#include <iostream>
using namespace std;
vector<int> parseInts(string str) {
vector<int> result;
stringstream ss(str);
string single_value;
while (getline(ss, single_value, ',')) {
result.push_back(stoi(single_value));
}
return result;
}
int main() {
string str;
cin >> str;
cin.ignore();
vector<int> integers = parseInts(str);
for (int i : integers) {
cout << i << endl;
}
return 0;
}