怎么找到最长子串位置
程序员文章站
2022-05-01 17:52:18
怎么找到最长子串位置
#include
#include
#include
using namespace std;
//--------------------------...
怎么找到最长子串位置 #include #include #include 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)); }