题解 | #字符串中找出连续最长的数字串#
字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/bd891093881d4ddf9e56e7cc8416562d
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
getline(cin, str);
int size = 0;
size_t len = str.size();
int pos = 0;
for (size_t i = 0; i < len; i++) {
int _size = 0;
size_t _cur = i;
while (_cur < len && str[_cur] <= '9' && str[_cur] >= '0') {
_size++;
_cur++;
}
if (_size > size) {
pos = i;
size = _size;
}
i = _cur;
}
cout << str.substr(pos, size) << endl;
return 0;
}
// 64 位输出请用 printf("%lld")

查看8道真题和解析