String stream - click here for tutorial
Code :
#include <sstream>
#include <vector>
#include <iostream>
using namespace std;
vector<int> parseInts(string str) {
// Complete this function
vector<int> v;
stringstream ss(str);
char ch;
int n;
while(!ss.eof()){
ss>>n>>ch;
v.push_back(n);
}
return v;
}
int main() {
string str;
cin >> str;
vector<int> integers = parseInts(str);
int sz = integers.size();
for(int i = 0; i < sz; i++) {
cout << integers[i] << "\n";
}
return 0;
}
No comments:
Post a Comment