K12教育赛事综合服务平台
聚乐之家官方网站
下载聚乐之家官方App
专注青少年竞赛题库网站
已知学生结构体定义如下:
struct Student { std::string name; int score; };
现有一个存储Student对象的std::vector<Student> stu_vec,需要对其按学生成绩从高到低进行降序排序,下列选项中的代码可以正确完成该需求的是?
std::sort(stu_vec.begin(), stu_vec.end(), std::greater<Student>());
std::sort(stu_vec.begin(), stu_vec.end(), [](const Student& a, const Student& b) { return a.score < b.score; });
std::sort(stu_vec.begin(), stu_vec.end(), [](const Student& a, const Student& b) { return a.score > b.score; });
std::sort(stu_vec.begin(), stu_vec.end());