难点:
1. 想到通过既没有ascender和decender的子串是连续的
2.通过逆向,得到非acender和非decender的字符,然后通过find_first_of找到符合要求的所有子串的起点
3.通过搜索判断后续字符是否是非ascender和decender
4.通过比较长度,保留最长子串
string test25(const string& str)
{
const string target = "acemnorsuvwxz";
int pos = 0,post=0,max=0;
string res="";
while ((pos = str.find_first_of(target, pos)) != string::npos)
{
post = pos + 1;
while (target.find(str[post]) != string::npos)
{
++post;
}
if (post - pos > max)
{
max = post - pos;
res = str.substr(pos, max);
}
pos = post + 1;
}
return res;
}
CPP萌新,请大佬们多指教,有错误请评论区指出,谢谢!