// 遍历字符串,记录最长的数字串,同时保存在vector数组中 #include <cctype> #include <iostream> #include <vector> using namespace std; int main() { string str; while(cin >> str){ int cur = 0, maxLen = 0, pos = 0; vector<string> ans; int len = str.length(); for(int i = 0; i < len; ++i){ if(isdigit(str[i])){ cur++; }else{ if(cur > maxLen){ ans.clear(); maxLen = cur; pos = i - maxLen; ans.push_back(str.substr(pos, maxLen)); } else if(cur == maxLen){ pos = i - maxLen; ans.push_back(str.substr(pos, maxLen)); } cur = 0; } } if(cur > maxLen){ ans.clear(); maxLen = cur; pos = len - maxLen; ans.push_back(str.substr(pos, maxLen)); }else if(cur == maxLen){ pos = len - maxLen; ans.push_back(str.substr(pos, maxLen)); } for(auto it : ans){ cout << it; } cout << "," << maxLen<< endl; } } // 64 位输出请用 printf("%lld")