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 }
原文地址:https://www.cnblogs.com/zhangqiling/p/12425787.html
时间: 2024-11-05 18:56:21