题解 | #成绩排序#

成绩排序

http://www.nowcoder.com/practice/0383714a1bb749499050d2e0610418b1

#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
bool cmp1(const pair<string, int> p1, const pair<string, int> p2) {
     return p1.second > p2.second;
}
bool cmp2(const pair<string, int> p1, const pair<string, int> p2) {
     return p1.second < p2.second;
}
int  main()
{
    std::ios::sync_with_stdio(false);
    int n,sel,score;
    string name;
    while(cin >> n){
        cin >> sel;
        vector<pair<string, int> > vec;
        while (n--) {
            cin >> name >> score;
            vec.push_back(pair<string, int>(name,score));
        }
        if(sel == 0)
            stable_sort(vec.begin(), vec.end(), cmp1);
        else
            stable_sort(vec.begin(), vec.end(), cmp2);
        for (auto it = vec.begin(); it != vec.end(); ++it)
            cout << (*it).first << " " << (*it).second << endl;
    }
    return 0;
}
全部评论

相关推荐

最喜欢秋天的火龙果很...:第一份工作一定要往大的去,工资低点没事。后面换工作会更好找,即使你去小公司,你也不可能不会换工作的。所以找大的去
点赞 评论 收藏
分享
03-06 20:09
贵州大学 Java
King987:你这个学历找个中大厂刷实习经历都是可以的,但是项目要有亮点才行,这个什么外卖就不要做了,去找找最新的项目,至少涉及高并发或者是新型的AI技术mcp rag啥的 ,我在出简历点评,但是你这个没什么好点评的,内容太少,而且含金量太低。自己改一改吧,或者看一下我的项目地址中,那里有大厂最近做过的实习项目
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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