结构体排序
成绩排序
http://www.nowcoder.com/questionTerminal/8e400fd9905747e4acc2aeed7240978b
成绩排序
http://www.nowcoder.com/questionTerminal/8e400fd9905747e4acc2aeed7240978b
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct stu{
string name;
int score;
}student[200];
bool cmp1(stu a,stu b){
return a.score < b.score;
}
bool cmp2(stu a,stu b){
return a.score > b.score;
}
int main()
{
int num,flag;
while(cin >> num >> flag){
for(int i = 0;i < num;i ++){
cin >> student[i].name >> student[i].score;
}
if(flag) stable_sort(student,student + num,cmp1);
else stable_sort(student ,student + num,cmp2);
for(int j = 0;j < num;j ++){
cout << student[j].name << " " << student[j].score << endl;
}
}
return 0;
}
相关推荐
牛客96609213...:疯狂背刺,之前还明确设置截止日期,还有笔试,现在一帮人卡在复筛,他反而一边开启扩招,还给扩招的免笔试,真服了,你好歹先把复筛中的给处理了再说