We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
vector parseInts(string str) {
int a;
char ch;
vector integers;
stringstream ss(str);
for (int i = 0; i < str.size()+1; i++)
{
if (str[i] == ',')
{
ss >> a >> ch;
integers.push_back(a);
}
}
ss >> a >> ch;
integers.push_back(a);
return integers;
}
int main() {
string str;
cin >> str;
vector integers = parseInts(str);
for(int i = 0; i < integers.size(); i++)
{
cout << integers[i] << "\n";
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
StringStream
You are viewing a single comment's thread. Return to all comments →
include
include
include
using namespace std;
vector parseInts(string str) { int a; char ch; vector integers; stringstream ss(str); for (int i = 0; i < str.size()+1; i++) { if (str[i] == ',') { ss >> a >> ch; integers.push_back(a); } } ss >> a >> ch; integers.push_back(a); return integers; }
int main() { string str; cin >> str; vector integers = parseInts(str); for(int i = 0; i < integers.size(); i++) { cout << integers[i] << "\n"; } return 0; }