【发布时间】:2009-10-07 02:20:19
【问题描述】:
我们有一个函数longest,它返回由字母组成的最长子串。示例:
longest("112****hel 5454lllllo454")
会返回:lllllo
但是,当我运行程序时,它似乎返回 lllllo454。这是函数:
char *longest(char *s){
char *pMax = NULL;
int nMax = 0;
char *p = NULL;
int n = 0;
int inside = 0; //flag
while(*s!='\0'){
char c = *s;
if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')){
if(inside == 0){
n = 1;
p = s;
inside = 1;
}
else
n++;
if(inside == 1){
if(n > nMax){
nMax = n;
pMax = p;
inside = 0;
}
}
}//end isLetter if
s++;
}
return pMax;
}
这里有一些我没有看到的东西……你们怎么看?
【问题讨论】: