#include <sstream>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
vector<int> parseInts(string str) {
char *sp= NULL;
vector<int> int_vect;
int length = str.size(); // length of the input string
int intarr[length];
int intcount =0, data=0, multi =1;
// Copy the string to a local string
string tempstr = str + ',';
// use the temp sring for operation
for (int i=0; i<=length; i ++ ){
if(tempstr[i] != ',' ){
data=(data*multi)+(tempstr[i]-'0');
if(multi != 10)
multi = multi*10;
else
multi = 10;
}
else{
int_vect.push_back (data);
multi = 1;
data =0;
}
}
return int_vect;
}
int main() {
string str;
cin >> str;
vector<int> integers = parseInts(str);
for(int i = 0; i < integers.size(); i++) {
cout << integers[i] << "\n";
}
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.