Solved: 23 - Associative Containers
This commit is contained in:
@@ -4,18 +4,25 @@ namespace stl_containers {
|
|||||||
|
|
||||||
auto word_frequencies(const std::vector<std::string>& words)
|
auto word_frequencies(const std::vector<std::string>& words)
|
||||||
-> std::map<std::string, int> {
|
-> std::map<std::string, int> {
|
||||||
(void)words;
|
auto m = std::map<std::string, int>();
|
||||||
return {};
|
for (const auto& word : words) {
|
||||||
|
++m[word];
|
||||||
|
}
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto unique_sorted(const std::vector<int>& data) -> std::set<int> {
|
auto unique_sorted(const std::vector<int>& data) -> std::set<int> {
|
||||||
(void)data;
|
auto s = std::set<int>();
|
||||||
return {};
|
for (const auto& value : data) {
|
||||||
|
s.insert(value);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto invert_map(const std::map<int, std::string>& input) -> std::map<std::string, int> {
|
auto invert_map(const std::map<int, std::string>& input) -> std::map<std::string, int> {
|
||||||
(void)input;
|
auto m = std::map<std::string, int>();
|
||||||
return {};
|
for (const auto&[k, v] : input) m[v] = k;
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace stl_containers
|
} // namespace stl_containers
|
||||||
|
|||||||
Reference in New Issue
Block a user