#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<string,int>A,pair<string,int>B)
{
//return A.second > B.second;//对map的第二个值排序
return A.first > B.first;//对第一个值排序。
}
int main()
{
map<string,int>x;
x["uu"]=1;
x["yy"]=5;
x["xx"]=2;
x["bb"]=6;
x["aa"]=0;
vector < pair<string,int> > str (x.begin(),x.end());//将map转化为vector函数储存。
sort(str.begin(),str.end(),cmp);//对vector函数进行排序
for(vector < pair<string,int> > :: iterator it=str.begin();it!=str.end();it++ )
{
cout << it->first << " " << it->second <<endl;
}
return 0;
}
05-10
03-09
139
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-17
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交