stable_sort函数的用法。
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct Node{
int num, sco;
string name;
};
bool cmp(Node a, Node b){
return a.sco > b.sco;
}
int main(){
int t, n;
Node stu;
cin >> t;
while(t--){
cin >> n;
vector<Node> vec;
while(n--){
cin >> stu.num >> stu.name >> stu.sco;
vec.push_back(stu);
}
stable_sort(vec.begin(), vec.end(), cmp);
for(int i = 0; i != vec.size(); ++i)
cout << vec[i].num << ' ' << vec[i].name << ' ' << vec[i].sco << endl;
vec.clear();
}
return 0;
}