25 .求字符串中连续最长的数字串

 这个没什么技巧,遍历,如果1个字符是数字符的话,那么以它为起点遍历,寻找以它为起点的连续的数字串的长度,下一次起点是这个连续字符串的下一个位置,保存1个最大长度和一个指向最长连续数字串的指针

/*
     求字符串中连续最长的数组串
 */

#include<stdio.h>
#include<iostream>
using namespace std;

#define MAX 100

int continumax(char* outputstr,char* inputstr)
{
    char* p=inputstr;
    char* q=NULL;
    char* k=NULL;
    int length=0;
    
    while(*p!='')
    {
        if(*p>='0'&&*p<'9')
        {
            q=p;
            k=p;
            int count=0;
            while(*q>='0' && *q<='9')
            {
                count++;
                q++;
            }
            if(count>=length)
                length=count;
            p=q;
        }
        else
            p++;
    }
    
    int i=0;
    while(i<length)
    {
        *(outputstr+i)=*(k+i);
        ++i;
    }
    *(outputstr+i)='';

    return length;
}

int main(void)
{
    char inputstr[MAX];
    char outputstr[MAX];

    scanf("%s",inputstr);
    continumax(outputstr,inputstr);
    cout<<outputstr<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/buxianghe/p/3262330.html