zoukankan      html  css  js  c++  java
  • [华为]在字符串中找出连续最长的数字串

    链接:https://www.nowcoder.com/questionTerminal/2c81f88ecd5a4cc395b5308a99afbbec
    来源:牛客网

    样例输出

    输出123058789,函数返回值9

    输出54761,函数返回值5

    接口说明

    函数原型:

       unsignedint Continumax(char** pOutputstr,  char* intputstr)

    输入参数:
       char* intputstr  输入字符串;

    输出参数:
       char** pOutputstr: 连续最长的数字串,如果连续最长的数字串的长度为0,应该返回空字符串;如果输入字符串是空,也应该返回空字符串;  

    返回值:
      连续最长的数字串的长度

    输入描述:

    输入一个字符串。


    输出描述:

    输出字符串中最长的数字字符串和它的长度。如果有相同长度的串,则要一块儿输出,但是长度还是一串的长度

    输入例子:
    abcd12345ed125ss123058789
    
    输出例子:
    123058789,9

    #include <iostream>
    #include <string>
    
    using namespace std;
    int main()
    {       
        string str;    
        while( cin>>str )    
        {        
            int i;        
            int max = 0;       
            string ss;        
            string out;        
            
            for(i = 0; i < str.size(); i++)        
            {           
                if(str[i] >= '0' &&str[i] <= '9')            
                {                
                    ss += str[i];                
                    while(str[i+1] >= '0' &&str[i+1] <= '9')                
                    {                    
                        i++;                   
                        ss += str[i];               
                    }                
                    
                    if(ss.size() > max)                
                    {                   
                        max = ss.size();                   
                        out = ss;                                  
                    }                
                    
                    else if(ss.size() == max)                   
                        out += ss;            
                }             
                ss.clear();                   
            }       
            cout<<out<<','<<max<<endl;           
        }    
        return 0;
    }
    

      








  • 相关阅读:
    test
    VS dll 引用依赖
    Git配置
    编码--文字输入的前因后果
    base64相关
    异或
    UNION / UNION ALL 区别
    数据库使用规范
    chrome插件开发学习(一)
    缓存穿透 缓存雪崩 缓存并发
  • 原文地址:https://www.cnblogs.com/hellochennan/p/6671197.html
Copyright © 2011-2022 走看看