sort中使用排序函数对大整数排序
作者:
xianhai
,
2021-12-06 19:38:08
,
所有人可见
,
阅读 251
void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);
http://www.cplusplus.com/reference/algorithm/sort/?kw=sort
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 105;
string a[N];
int n;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n, [](string a, string b){
if (a.size() == b.size()) {
return a < b;
}
return a.size() < b.size();
});
for (int i = 0; i < n; i++) {
cout << a[i] << endl;
}
return 0;
}