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

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

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

#define _CRT_SECURE_NO_WARNINGS 1
#include
using namespace std;
#include
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;
}

网页题目:字符串中找出连续出现的最大数字字符串
文章URL:http://ybzwz.com/article/gpscpc.html