C++ sort 比较函数,lambda 和结构体写法:

1
2
3
4
5
6
7
8
9
10
struct comp {
bool operator()(const int x, const int y) {
return x < y;
}
};
sort(nums.begin(), nums.end(), [](int x, int y) {
string a = to_string(x), b = to_string(y);
return a+b>b+a;
});
sort(nums.begin(), nums.end(), comp);