字符串中找出连续出现的最大数字字符串

字符串中找出连续出现的最大数字字符串

专注于为中小企业提供做网站、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业青铜峡免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了1000多家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
#include<string>
int main()
{
    string s1;
    while (getline(cin, s1))
    {
        int newlen = 0;//统计数字字符的长度
        int max=0;//数字字符的最大长度
        auto start = s1.begin();
        auto finish = s1.begin();
        string s2;
        while (start != s1.end()&&finish!=s1.end())
        {
            if (*start >= '0'&&*start <= '9')
            {
                newlen = 0;
                finish = start;
                while (finish != s1.end() && *finish >= '0'&&*finish <= '9'&&finish != s1.end())
                    //算出从当前位置起连续数字的最大值
                {
                    finish++;
                    newlen++;
                }
                if (newlen > max)//如果比之前的最大值大则替换
                {
                    s2.clear();
                    while (start != finish)
                    {
                        s2.push_back(*start);
                        start++;
                    }
                    max = newlen;
                }
                else//没之前的大就让start继续往后走
                {
                    start++;
                }
            }
            else
            {
                start++;
            }
        }
        cout << s2 << endl;
        s1.clear();
        s2.clear();
    }
    system("pause");
    return 0;
}

文章标题:字符串中找出连续出现的最大数字字符串
分享地址:https://www.cdcxhl.com/article32/gpscpc.html

成都网站建设公司_创新互联,为您提供软件开发外贸建站小程序开发网站排名手机网站建设自适应网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

手机网站建设