题解 | #成绩排序#

成绩排序

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")

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务