feat(cpp): implement ‹collect_count›

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2024-02-28 12:25:12 +01:00
parent 5fa844da30
commit 78e46a06ff
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -150,6 +150,19 @@ Container collect(std::size_t size) {
collect(c, size); collect(c, size);
return c; return c;
} }
template <typename T>
std::map<T, std::size_t> collect_count(std::size_t size) {
std::map<T, std::size_t> counts;
for (auto i = 0u; i < size; ++i) {
T x;
std::cin >> x;
++counts[x];
}
return counts;
}
#pragma endregion /* input */ #pragma endregion /* input */
#pragma region math #pragma region math