第28464题 单选题
如下C++代码运行后的输出结果是?
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

struct Student {
    string name;
    int score;
};

// 自定义比较函数
bool compare(const Student& a, const Student& b) {
    return a.score > b.score;
}

int main() {
    vector<Student> students = {{"Alice", 85}, {"Bob", 92}, {"Charlie", 78}};
    sort(students.begin(), students.end(), compare);
    for(const auto& s : students) {
        cout << s.name << " ";
    }
    return 0;
}
A

Alice Bob Charlie

B

Bob Alice Charlie

C

Charlie Alice Bob

D

Bob Charlie Alice

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