#include <stdio.h> char * maxsubstr(char * str,int &maxn) { int n; char * p=str, * maxp=p; maxn=1; while ( * p) { n=1; while ( * (p+1) && * p== * (p+1)) { n++; p++; } if (n>maxn) { maxn=n; maxp=p-n+1; } p++; } return maxp; } void main() { char str[ ]="122221333333"; char * p; int n,i; p=maxsubstr(str,n); printf("最长子串:"); for (i=0;i<n;i++ ) printf("%c", * p++ ); printf("\n"); }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题