0
Hello, I don't know how to find the first string in array with longest length?
2 ответов
+ 1
Why that much complicating the task..?
Simply iterate vector through loop
And take each string into a string variable string s = vector[i];
int len = s.length() ;
Then find is it maximum! If maximum swap with previous values..
Finally print max length string...
edit :
TeaserCode
std::string LongestConsec::longestConsec(const std::vector<std::string> &strarr, int k) {
std::string result;
int d = strarr.size(), max=0;
for( int i=0; i<d; i++ ) {
std::string s = strarr[i];
int l = s.length();
if(max <= l){
max = l;
result = s;
}
}
return result;
}