题解 | #成绩排序#

成绩排序

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

#include <iostream>
#include <map>
using namespace std;
//这里使用mutilmap里的自动排序,将成绩和姓名进行调换,将成绩作为key进行排序
//如果==0就用降序 ==1用升序
int main() {
    int n, comp;
    while (cin >> n) { 
        cin >> comp;
        if (comp == 0) {
            multimap<int, string, greater<int>> m1;
            for (int i = 0; i < n; i++) {
                string s;
                int k;
                cin >> s;
                cin >> k;
                m1.emplace(k, s);
            }
            for(auto e :m1)
            {
                cout<<e.second<<" "<<e.first<<endl;
            }
        } else if (comp == 1) {
            multimap<int, string> m1;
            for (int i = 0; i < n; i++) {
                string s;
                int k;
                cin >> s;
                cin >> k;
                m1.emplace(k, s);
            }
            for(auto e :m1)
            {
                cout<<e.second<<" "<<e.first<<endl;
            }
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

pdd已经一面了,听说pdd是11116听着已经压力巨大了但是听说给的多投都投了,先面着吧
码农索隆:我认为哈,工资高加班多那是正常的,加班费啥的都正常给,那是ok的,但是加班多没加班费逼事还一堆一堆的那种公司,没必要进,进去之后,都不用吃饭,没事,就吃大饼
点赞 评论 收藏
分享
熊大不大:恭喜恭喜,我也注册美团众包成功了
投递美团等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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