1.年龄大的在前
2.年龄一样名字首字母按a~z排序
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct node {
string t;
int value;
};
bool cmp(const node &a, const node &b) {
return a.value != b.value ? a.value > b.value : a.t < b.t;
}
int main() {
unordered_map<string,int> m;
m["fa"]=23;
m["sun"]=24;
m["ana"]=23;
m["wan"]=4;
vector<node> ans;
for(auto it : m){
node n={it.first,it.second};
ans.push_back(n);
}
sort(ans.begin(),ans.end(),cmp);
for(int j=0;j<ans.size();j++)
{
printf("%s %d\n",ans[j].t.c_str(),ans[j].value);
}
return 0;
}