题解
2023-08-20 15:11:14
发布于:广东
4阅读
0回复
0点赞
严格遵守知识点标签(快排)
#include <bits/stdc++.h>
using namespace std;
struct Student {
string id;
string name;
int score;
};
int partition(vector<Student>& students, int low, int high) {
Student pivot = students[high];
int i = low - 1;
for (int j = low; j < high; ++j) {
if (students[j].id < pivot.id) {
i++;
swap(students[i], students[j]);
}
}
swap(students[i + 1], students[high]);
return i + 1;
}
void quickSort(vector<Student>& students, int low, int high) {
if (low < high) {
int pivotIdx = partition(students, low, high);
quickSort(students, low, pivotIdx - 1);
quickSort(students, pivotIdx + 1, high);
}
}
int main() {
int n;
cin >> n;
vector<Student> students(n);
for (int i = 0; i < n; ++i) {
cin >> students[i].id >> students[i].name >> students[i].score;
}
quickSort(students, 0, n - 1);
for (Student student : students) {
cout << student.score << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个