题解 | #小白鼠排队# - map小题大做法

小白鼠排队

https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b

#include <bits/stdc++.h>
using namespace std;

struct compare{
    bool operator()(const int& a, const int& b) const{
        return a > b;
    }
};

int main(){
    map<int, string ,compare> m;
    int n;
    while(cin >> n){
        if(n == 0 ) break;

        for(int i = 0 ; i <n ; i++){
            int weight;
            string color;
            cin >> weight >> color;
            m[weight] = color;
        }

        for(auto& mou : m){
            cout << mou.second << endl;
            //mou.first 会访问这个对的第一部分,即键(这里是白鼠的重量)。
            //mou.second 访问这个对的第二部分,即值(这里是白鼠的帽子颜色)。
        }
        m.clear();
    }
}

全部评论

相关推荐

面了100年面试不知...:今年白菜这么多,冬天可以狂吃了
点赞 评论 收藏
分享
11-07 16:07
深圳大学 运营
前端飞升:学长,阿里不是卡双非吗,我深也能去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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