华为面试题答案找出最大长度子字符串_C语言教程-查字典教程网
华为面试题答案找出最大长度子字符串
华为面试题答案找出最大长度子字符串
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:intfindMaxSubstring(char*str){intmaxLength=0;intmaxStartIndex...

复制代码 代码如下:

int findMaxSubstring(char* str)

{

int maxLength = 0;

int maxStartIndex = 0;

int curLength = 0;

int curStartIndex = 0;

bool isFind = 0;

for(unsigned int i = 0;i<strlen(str);i++)

{

if(str[i] >= 'a' && str[i] <= 'z')

{

if(isFind == 0)

{

isFind = 1;

curLength = 1;

curStartIndex = i;

}

else

{

curLength++;

}

}

else if (str[i] < 'a' || str[i] > 'z')

{

isFind = 0;

if(curLength > maxLength)

{

maxLength = curLength;

maxStartIndex = curStartIndex;

curLength = 0;

}

}

}

char *p = NULL;

p = &str[maxStartIndex];

while(*p >= 'a' && *p <= 'z')

{

putchar(*p);

p++;

}

return maxLength;

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新C语言学习
    热门C语言学习
    编程开发子分类