寻找字符串中最大一段

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

//寻找input中最长的数字串  ad9ef98aef9ef89afq1234  返回最长数字串长度 并将数字串存入output
int find(char*output, char* input)
{
    char* in = input;
    char* temp = NULL;
    char* final = NULL;
    int count=0;
    int max=0;
    while(*in !='')
    {
        if(*in>47 && *in<58)
        {
            for(temp = in; *in>47 && *in<58;in++)
            {
                count++;
            }
        }
        else
            in++;
        if(max< count)
        {
            max = count;
            final = temp;
        }
        count=0;
    }
    for(int i=0; i<max; i++)
    {
        *output++ = *final++;
    }
    *output = '';
    return max;
}

//递归反向输出
void reverse(char* p)
{
    if(*p == '')
    {
        return ;
    }
    else
    {
        reverse(p+1);
    }
    printf("%d",*p);
}
void Reverse(char* p, char* q)
{
    while(p< q)
    {
        char temp = *p;
        *p++ = *q;
        *q-- = temp;
    }
}

char* Mystrcpy(char* dest, const char* src)
{
    if( (NULL==dest) ||(NULL ==src) )
    {
        assert(false);
    }
    char* temp = dest;
    while( (*dest++ = *src++)  != '')
    return temp;
}

int main()
{
    char str[] ="93nu29n3ns93n1234";
    char dest[10]= " ";
    int b =find(dest, str);

    return 0;
}

void fun(char* src)
{
    char temp = '';
    int Num =0;
    for(int i=0; i<strlen(src); i++)
    {
        if(temp !=src[i])
        {
            if(0 != i)
            {
                cout<<temp<<Num<<endl;
            }
            temp = src[i];
            Num=1;
        }
        else
        {
            Num++;
        }
    }
    cout << temp<< Num<<endl;
}

关注公众号 海量干货等你
原文地址:https://www.cnblogs.com/sowhat1412/p/12734411.html