C++Map按Value排序

2021-06-22 20:08

阅读:600

标签:mes   name   include   algo   bool   string   opera   span   typedef   

#include 
#include 
#include 
#include string>
#include 
#include using namespace std;

typedef pairstring,int> PAIR;

struct cmp
{
    bool operator()(const pairstring,int> &p1,const pairstring,int> &p2)
    {
        return p1.second > p2.second;
    }
};

int main()
{
    mapstring,int>mp;

    for(int i=0;i100;i+=10)
    {
        stringstream ss;
        ssi;
        string si = "m" + ss.str();
        mp.insert(make_pair(si,i));
    }

    for(mapstring,int>::iterator it = mp.begin();it!=mp.end();it++)
    {
        coutfirst "  " second endl;
    }

    vectorstring,int>>vt(mp.begin(),mp.end());

    sort(vt.begin(),vt.end(),cmp());

    for(vectorstring,int>>::iterator it=vt.begin();it != vt.end();it++)
    {
        coutfirst "  " second endl;
    }

    return 0;
}

 

C++Map按Value排序

标签:mes   name   include   algo   bool   string   opera   span   typedef   

原文地址:https://www.cnblogs.com/achao123456/p/9676524.html


评论


亲,登录后才可以留言!