题解 | #大整数排序#
大整数排序
https://www.nowcoder.com/practice/b744af632ac4499aa485d7bb048bb0aa
加油,就是字符串排序。不过这里我们需要稍微改进一下默认的排序。
#include <iostream> #include <algorithm> #include <vector> #include <string.h> using namespace std; int main() { int n; while (cin >> n) { vector<string> f; for (int i = 0; i < n; i++) { string s; cin >> s; f.emplace_back(s); } sort(f.begin(), f.end(), [](string a, string b) { if (a.length() != b.length()) return a.length() < b.length(); return a < b; }); for (int i = 0; i < n; i++) cout << f[i] << endl; } }