C++期末考试成绩排名
时间: 2023-10-27 19:08:22 浏览: 163
C++实现成绩排名
4星 · 用户满意度95%
好的,针对你的问题,我可以提供以下代码实现:
```c++
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Student {
string name;
int score;
};
bool cmp(Student a, Student b) {
return a.score > b.score;
}
int main() {
int n;
cin >> n;
vector<Student> students(n);
for (int i = 0; i < n; i++) {
cin >> students[i].name >> students[i].score;
}
sort(students.begin(), students.end(), cmp);
for (int i = 0; i < n; i++) {
cout << students[i].name << " " << students[i].score << endl;
}
return 0;
}
```
阅读全文