INPUT
输入一个字符串
OUTPUT
输出字符串中最长的数字字符串和它的长度。如果有相同长度的串,则要一块儿输出,但是长度还是一串的长度
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
while (cin >> s) {
int max = 0;
vector<string> v;
int tmp = 0;
for (int i = 0; i<s.size();) {
string tmp_s;
if (s[i] >= '0'&&s[i] <= '9') {
for (int j = i; j<s.size(); j++) {
if (s[j] >= '0'&&s[j] <= '9') {
tmp++;
tmp_s += s[j];
}
else {
break;
}
}
v.push_back(tmp_s);
i += tmp;
max = (tmp>max) ? tmp : max;
}
else {
tmp = 0;
i++;
}
}
string ans;
for (auto i : v) {
if (i.size() == max)
ans += i;
}
cout << ans << "," << max << endl;
}
}