文章
59
粉丝
0
获赞
320
访问
7.4k
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
using namespace std;
typedef struct{
string name;
int score;
}stu;
bool comp_des(stu x,stu y)
{
return x.score>y.score;
}
bool comp_asc(const stu &x,const stu &y)
{
return x.score<y.score;
}
int main()
{
int n, method;
string s;
int num;
vector<stu> se;//se sequence
while (cin >> n >> method)
{
for (int i = 0; i < n; i++)
{
cin >> s >> num;
se.push_back({ s,num });
}
if (method)
stable_sort(se.begin(), se.end(),comp_asc);
else
stable_sort(se.begin(), se.end(), comp_des);
for (int i = 0; i < n; i++)
cout << se[i].name << " " << se[i].score << endl;
se.clear();
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发