> vec(map.begin(), map.end()); // map을 vector로 변경 sort(vec.begin(), vec.end(), cmp); for (auto elem : vec) { cout << elem.first << endl; } }"> > vec(map.begin(), map.end()); // map을 vector로 변경 sort(vec.begin(), vec.end(), cmp); for (auto elem : vec) { cout << elem.first << endl; } }"> > vec(map.begin(), map.end()); // map을 vector로 변경 sort(vec.begin(), vec.end(), cmp); for (auto elem : vec) { cout << elem.first << endl; } }">
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <iostream>
using namespace std;
bool cmp(pair<string, int>& a, pair<string, int>& b)
{
return a.second < b.second;
}
int main()
{
unordered_map<string, int> map;
map["a"] = 6;
map["b"] = 1;
map["c"] = 4;
map["d"] = 8;
vector<pair<string, int>> vec(map.begin(), map.end()); // map을 vector로 변경
sort(vec.begin(), vec.end(), cmp);
for (auto elem : vec)
{
cout << elem.first << endl;
}
}