#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
//---------------------------------
char* findMaxStr(char* ch)
{
char *maxP, *temP;
int maxN, currentMaxN;
maxP = temP = ch;
maxN = currentMaxN = 1;
while (*ch) {
if (*(ch + 1) == (*ch) + 1) {
currentMaxN++;
} else {
if (currentMaxN > maxN) {
maxN = currentMaxN;
maxP = temP;
}
temP = ch + 1;
currentMaxN = 1;
}
ch++;
}
*(maxP + maxN) = '\0';
return maxP;
}
int main()
{
char sourceStr[] = "abcdewrdfadq12345678000";
printf("result: %s", findMaxStr(sourceStr));
}
找到最长子串位置
最新推荐文章于 2023-02-27 16:54:55 发布