文章
68
粉丝
691
获赞
26
访问
577.9k
int main() {
int ma = 0; string res, s;
while (getline(cin, s)) {
s += ' ';//最后加一个空格
int i = 0, beg = 0, sum = 0; string res;
while (i < s.size()) {
if (s[i] != ' ')i++;
else {
string t = s.substr(0, i);
s = s.substr(i + 1); i = 0;
while (s[0] == ' ')s = s.substr(1);//过滤前导0
cout << t << ' ' << t.size() << endl;
if (t.size() > sum) {
sum = t.size(); res = t;
}
}
}
cout << "The longest word is: " << res << endl;
}
}
登录后发布评论
暂无评论,来抢沙发