This V returns for me exit code 139 - which means it's has a undefined behaviour. I really don't understand why. This function returns the longest possible string from K consecutive strings.
std::string longestConsec(std::vector<std::string> &strarr, int k){
for(int i=0;i<strarr.size();i++){
std::cout<<strarr[i]<<std::endl;
}
int maxi{}, m{};
std::string result{}, r{};
for(int i = 0;i<=strarr.size()-k;i++){
for(int j = i;j<i+k;j++){
m+=strarr[j].length();
r+=strarr[j];
}
if(m>maxi){
result = r;
maxi = m;
}
m = 0;
r = "";
}
return result;
}
Comments
Post a Comment