K12教育赛事综合服务平台
聚乐之家官方网站
下载聚乐之家官方App
专注青少年竞赛题库网站
本题考查C++ STL std::sort的自定义比较器使用规则,需注意比较函数需满足严格弱序要求。
std::sort(vec.begin(), vec.end(), [](const Student& a, const Student& b) { return a.score < b.score; });
std::sort(vec.begin(), vec.end(), [](const Student& a, const Student& b) { return a.score > b.score; });
std::sort(vec.begin(), vec.end(), [](const Student& a, const Student& b) { return a.score >= b.score; });
std::sort(vec.begin(), vec.end(), std::greater<int>());