题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/dfeed0e0e4624814b122265e859783b2
#include <cstdio> #include <functional> #include <iostream> #include <vector> using namespace std; bool com(string a,string b){ return a.size()<b.size(); } int main() { int n; string str; vector<string> vec; while (cin >> n) { vec.clear(); n=n+1; while (n--) { getline(cin, str); if (str == "stop") break; vec.push_back(str); } int u = vec.size(); sort(vec.begin(), vec.end(),com); cout<<vec[0]; for (int i = 1; i <u; i++) cout << vec[i] << endl; } } // 64 位输出请用 printf("%lld")