第28475题 单选题
现有C++结构体`struct Student { std::string name; int score; };`,若需要对存储该结构体对象的std::vector按学生成绩从高到低降序排序,以下哪个选项的std::sort调用代码是正确的?

本题考查C++ STL std::sort的自定义比较器使用规则,需注意比较函数需满足严格弱序要求。

A

std::sort(vec.begin(), vec.end(), [](const Student& a, const Student& b) { return a.score < b.score; });

B

std::sort(vec.begin(), vec.end(), [](const Student& a, const Student& b) { return a.score > b.score; });

C

std::sort(vec.begin(), vec.end(), [](const Student& a, const Student& b) { return a.score >= b.score; });

D

std::sort(vec.begin(), vec.end(), std::greater<int>());

程序运行统计
暂无判题统计
提交0次 正确率0.00%
答案解析