输出字符串中最长的数字字符串

输入描述:

输入一个字符串。

输出描述:

输出字符串中最长的数字字符串。

输入例子:
abcd12345ed125ss123058789
输出例子:
输出123058789
#include<iostream>
#include<string>
using namespace std;
int main()
{
        string str;
        cin >> str;
        int len = str.length();
        int max_len = 0, start = 0;
        int count_len = 0, temp = 0;
        for(int i = 0; i < len; i++)
        {
                if(str[i] >= '0' && str[i] <= '9')
                {
                        if(count_len == 0)
                                temp = i;
                        count_len++;
                        if(max_len < count_len)
                        {
                                max_len = count_len;
                                start = temp;
                        }
                }
                else
                        count_len = 0;
        }
        for(int i = start; i < start+max_len; i++)
                cout << str[i] << " ";
}

点赞