题解 | #大整数排序#
大整数排序
https://www.nowcoder.com/practice/b744af632ac4499aa485d7bb048bb0aa
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; void print(string const s){ cout << s << endl; } bool compare(string s1, string s2){ if (s1.size() != s2.size())//长度不一样,长度短的更小 return s1.size() < s2.size(); else//两个字符串长度一样 return s1 < s2; } int main(){ int n; while (cin >> n){ vector<string> v; for (int i = 0; i < n; i++) { string s; cin >> s; v.push_back(s); } sort(v.begin(), v.end(), compare); for_each(v.begin(), v.end(), print); } return 0; }