#define _CRT_SECURE_NO_WARNINGS 1 #include<iostream> using namespace std; #include<string> int main() { string s1; while (getline(cin, s1)) { int newlen = 0;//統計數字字符的長度 int max=0;//數字字符的最大長度 auto start = s1.begin(); auto finish = s1.begin(); string s2; while (start != s1.end()&&finish!=s1.end()) { if (*start >= '0'&&*start <= '9') { newlen = 0; finish = start; while (finish != s1.end() && *finish >= '0'&&*finish <= '9'&&finish != s1.end()) //算出從當前位置起連續數字的最大值 { finish++; newlen++; } if (newlen > max)//若是比以前的最大值大則替換 { s2.clear(); while (start != finish) { s2.push_back(*start); start++; } max = newlen; } else//沒以前的大就讓start繼續日後走 { start++; } } else { start++; } } cout << s2 << endl; s1.clear(); s2.clear(); } system("pause"); return 0; }