zoukankan      html  css  js  c++  java
  • 寻找字符串中最大一段

    #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;
    }

    关注公众号 海量干货等你
  • 相关阅读:
    HashMap的实现原理
    LinkedHashMap的实现讲解
    ConcurrentHashMap原理分析
    javax.mail Java Extension(扩展)
    Singleton 单例模式
    Java序列化与反序列化(实践)
    Java IO操作
    Java NIO与IO的区别和比较
    java模拟异步消息的发送与回调
    java如何实现多个线程并发运行
  • 原文地址:https://www.cnblogs.com/sowhat1412/p/12734411.html
Copyright © 2011-2022 走看看