题解 | #成绩排序#

#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函数
全部评论

相关推荐

码农索隆:单休一个月少休息4天,一年就是48天,平时节假日,别人3天假期,单休的两天
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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