#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;
}
}
출력 결과
b
c
a
d
'C | C++' 카테고리의 다른 글
[C++] 최소값, 최대값 쉽게 구하는 방법 (0) | 2022.05.11 |
---|---|
[C++] string to int, char to int, int to string, int to char (0) | 2022.05.11 |
[Effetive C++] Chapter 1 정리 (0) | 2022.04.27 |
[Effective C++] 기초 정리 (0) | 2022.04.26 |
C++ STL Prioriy-Queue(우선순위큐) (0) | 2020.12.31 |