#include #include #include

using namespace std;

struct Student { string name; int score; };

bool cmp(Student a, Student b) { if (a.score == b.score) { return a.name < b.name; } return a.score > b.score; }

int main() { int n; cin >> n;

Student* students = new Student[n];
for (int i = 0; i < n; i++) {
    cin >> students[i].name >> students[i].score;
}

sort(students, students + n, cmp);

for (int i = 0; i < n; i++) {
    cout << students[i].name << " " << students[i].score << endl;
}

delete[] students;

return 0;
C++不使用vector头文件完成:给出班里某门课程的成绩单请你按成绩从高到低对成绩单排序输出如果有相同分数则名字字典序小的在前已保证不存在重名的情况。输入描述第一行为n 0 n 20表示班里的学生数目;接下来的n行每行为每个学生的名字和他的成绩 中间用单个空格隔开。名字只包含字母且长度不超过20成绩为一个不大于100的非负整数。输出描述把成绩单按分数从高到低的顺序进行排序并输出每行包含名字和

原文地址: http://www.cveoy.top/t/topic/hXFq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录