题解 | #成绩排序#

成绩排序

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

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

int main() {
    int Num;
    int op;
    cin >> Num >> op;

    vector<pair<string,int>> temp(Num);
    
    for (int i = 0;i < Num;i++)
    {
        cin >> temp[i].first >> temp[i].second;
    }

    if (op == 0)
    {
        stable_sort(temp.begin(),temp.end(),[](const pair<string,int>& a,const pair<string,int>& b){return a.second > b.second;});
    }
    else if (op == 1) 
    {
        stable_sort(temp.begin(),temp.end(),[](const pair<string,int>& a,const pair<string,int>& b){return a.second < b.second;});
    }

    for (auto it : temp)
    {
        cout << it.first << ' ' << it.second << endl;
    }


}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

09-08 17:17
同济大学 Java
狗不理fe:里面的人劝一句,别来虾,我们部门24校招生淘汰率30%,还有一些人说有一年保护期,不可能!!!
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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