- Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathc-tutorial-stringstream.cpp
More file actions
Latest commit
36 lines (29 loc) · 645 Bytes
/
Copy pathc-tutorial-stringstream.cpp
File metadata and controls
36 lines (29 loc) · 645 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
// https://www.hackerrank.com/challenges/c-tutorial-stringstream/problem
#include<sstream>
#include<vector>
#include<iostream>
usingnamespacestd;
vector<int> parseInts(const string& str) {
// Complete this function
stringstream ss(str);
vector<int> v;
while (! ss.eof())
{
int i;
ss >> i;
v.push_back(i);
char c;
ss >> c;
if (c != ',') break;
}
return v;
}
intmain() {
string str;
cin >> str;
vector<int> integers = parseInts(str);
for(size_t i = 0; i < integers.size(); i++) {
cout << integers[i] << "\n";
}
return0;
}