结构体排序

成绩排序

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



全部评论
结构体,c语言的影子
点赞 回复 分享
发布于 2021-03-28 08:41

相关推荐

09-29 16:59
已编辑
门头沟学院 Java
牛客96609213...:疯狂背刺,之前还明确设置截止日期,还有笔试,现在一帮人卡在复筛,他反而一边开启扩招,还给扩招的免笔试,真服了,你好歹先把复筛中的给处理了再说
投递大疆等公司10个岗位
点赞 评论 收藏
分享
纯真的河老师在喝茶:第一个是这个时间点岗位少,第二个是这个简历重复度太高了,10个有9个简历差不多的
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务