题解 | #成绩排序#

#include <iostream>
#include <algorithm>
#include<string>
using namespace std;

struct student {     string name;     int score;
};

bool cmp0(student x, student y) {     return x.score > y.score;
}

int main()
{     struct student stu[200];     int n, tag;     cin >> n >> tag;     for (int i = 0; i < n; i++) {         cin >> stu[i].name >> stu[i].score;     }     if (tag == 0) stable_sort(stu, stu + n, cmp0);     if (tag == 1) stable_sort(stu, stu + n, [](student x, student y) {return x.score < y.score; });     for (int i = 0; i < n; i++)             cout << stu[i].name << ' ' << stu[i].score << endl;
}

知识点:结构体。sort函数
全部评论

相关推荐

投递长鑫存储等公司8个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-01 17:13
想去,但是听说加班强度实在难崩,所以拒绝了,现在有点心梗对面hr感觉也是实习生,打电话的时候怪紧张的,但是感觉人很好嘞
水中水之下水道的鼠鼠:哥们这不先去体验一下,不行再跑呗,大不了混个实习经历(有更好的转正offer就当我没说)
点赞 评论 收藏
分享
头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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