题解 | #成绩排序#

成绩排序

https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b

#include <algorithm>
#include <iostream>
#include <bits/stdc++.h>
#include <utility>
#include <vector>
using namespace std;



int main() {
    int n;
    cin >> n;
    int flag;
    cin >> flag;
    vector<pair<string, pair<int, int>>> data(n);
    for (int i = 0; i < n; ++i) {
        string name;
        int score;
        cin >> name >> score;
        data[i] = {name, {score, i}};
    }
    if (flag) {
        sort(begin(data), end(data), [](pair<string, pair<int, int>>& a, pair<string, pair<int, int>>& b){return a.second.first != b.second.first ? a.second.first < b.second.first : a.second.second < b.second.second;});
    } else {
        sort(begin(data), end(data), [](pair<string, pair<int, int>>& a, pair<string, pair<int, int>>& b){return a.second.first != b.second.first ? a.second.first > b.second.first : a.second.second < b.second.second;});
    }
    for (const auto &[name, p] : data) {
        cout << name << " " << p.first << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-15 17:17
听说过付费实习,没想到这么贵啊我去,要不我给你个腰子吧
哈哈哈,你是老六:这种公司一定要注意啊,不要随便签合同,只要签了后面钱可能回不来,而且你通过法律途径也弄不回
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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