I participated in different coding contests and therefore cant use python cause it's too slow on execution time, but i really like the input.split() thing, so i tried to implement my own split. Here is what i came up with:
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
vector<string> splt(string s){
vector<string> ans={};
for(int i=0;i<s.size();i++){
string str="";
while(s[i]!=' '){
str+=s[i];
i++;
}
ans.push_back(str);
}
return ans;
}
int main(){
string s;
getline(cin, s);
vector<string> ans=splt(s);
for(auto i:ans)
cout<<i<<", ";
}
But the vector returned by the function often(but no always) has some junk at the end. Would appreciate any help with correcting my code, as well as some other impementation of splitting a string into an array.
P.S. Sorry if my English is bad, im from Russia and haven't even finished school :)