Gooooogle • 5个月前
#include <iostream>
#include <cstring>
using namespace std;
int main() {
string st, max_st, min_st;
int max_l = -1, min_l = 1000, t, k;
getline(cin, st);
st = " " + st + " ";
for (int i = 0; i < st.length() - 1; i++) {
if (st[i] != ' ' && st[i] != ',' && st[i] != '.') {
t = 1;
k = i;
while (st[i + 1] != ' ' && st[i + 1] != ',' && st[i + 1] != '.') {
t++;
i++;
}
if (t > max_l) {
max_l = t;
max_st = st.substr(k, t);
}
if (t < min_l) {
min_l = t;
min_st = st.substr(k, t);
}
}
}
cout << max_st << endl << min_st;
return 0;
}
评论:
请先登录,才能进行评论