Created
December 31, 2016 20:46
-
-
Save kazmura11/da5805242adee5aee33316f2c1066459 to your computer and use it in GitHub Desktop.
mapからvectorへ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <unordered_map> | |
#include <algorithm> | |
#include <iostream> | |
auto main()->int | |
{ | |
std::ios::sync_with_stdio(false); | |
// vector -> map | |
std::unordered_map<std::string, int> m {{"a",1},{"b",2},{"c",3},{"d",4}}; | |
std::vector<int> v; | |
std::transform(m.begin(), m.end(), back_inserter(v), | |
[](decltype(m)::value_type& kv) { return kv.second; }); | |
//一応valueででソート | |
sort(v.begin(), v.end()); | |
for (const auto& i : v) { | |
std::cout << i << ","; // => 1,2,3,4, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment