题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
#include <cctype> #include <iostream> #include <string> #include <vector> using namespace std; int main() { string strs; while(cin >> strs) { string max_str; int num = 0; vector<string> all_max_str; for (int i = 0;i < strs.size();i++) { if (isdigit(strs[i])) { max_str += strs[i]; } else { max_str.clear(); } if (max_str.size() > num) { num = max_str.size(); all_max_str.clear(); all_max_str.push_back(max_str); } else if (max_str.size() == num && num != 0) { all_max_str.push_back(max_str); } } for (auto it : all_max_str) { cout << it; } cout << "," << num << endl; } } // 64 位输出请用 printf("%lld")