国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C > 正文

華為面試題答案找出最大長度子字符串

2020-01-26 15:39:45
字體:
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:

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;
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 杂多县| 阿城市| 东阿县| 中江县| 醴陵市| 兴文县| 和平区| 措勤县| 盐边县| 乌拉特中旗| 上饶县| 大宁县| 遂溪县| 福海县| 仙居县| 平阴县| 城市| 凤翔县| 巴东县| 湘潭县| 紫阳县| 大丰市| 磐安县| 十堰市| 吉木乃县| 陆河县| 祁连县| 山东| 西昌市| 淮安市| 喀什市| 平乡县| 大关县| 溆浦县| 墨江| 慈利县| 秭归县| 南充市| 太康县| 临桂县| 泽州县|