zoukankan      html  css  js  c++  java
  • map按照值排序

     1 #include<bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 map<int,int/*,greater<int>*/>mp;
     6 //Tip: map按照key从大到小排序 map<int,int,greater<int>> mp;
     7 
     8 bool cmp(const pair<int,int> &a, const pair<int,int> &b){
     9     return a.second > b.second;
    10 }
    11 
    12 struct cmp2{
    13     bool operator () (const pair<int,int> &a, const pair<int,int> &b) const{
    14         return a.second > b.second;
    15     }
    16 };
    17 
    18 int main(){
    19     
    20     for(int i=1; i<=10; i++){
    21         mp[i] = 10 -i;
    22     }
    23     
    24     vector<pair<int,int>> v(mp.begin(),mp.end());
    25     sort(v.begin(),v.end(),cmp);
    26     //sort(v.begin(),v.end(),cmp2());
    27     for(int i=0; i<v.size(); i++){
    28         cout << v[i].first << " " << v[i].second << endl;
    29     }
    30     return 0;
    31 } 
  • 相关阅读:
    Socket listen 简要分析
    Socket connect 等简要分析
    HIVE函数大全
    元数据管理
    flume
    shell编程
    数据仓库集锦
    数据库知识
    hive sql 转化mapreduce原理
    Hadoop 学习笔记
  • 原文地址:https://www.cnblogs.com/zhangqiling/p/12425787.html
Copyright © 2011-2022 走看看