NYOJ871 比赛 stable_sort

原题链接

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;
}


posted on 2014-03-08 23:03  长木Qiu  阅读(134)  评论(0编辑  收藏  举报