#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
void count(std::vector<int> arr){
std::sort(arr.begin(), arr.end());
int frequency = 1;
for (int x =0; x < arr.size()-1; x ++){
if(arr[x]==arr[x+1]){
frequency ++;
}
else{
std::cout << arr[x] << ": " << frequency << std::endl;
frequency = 1;
}
}
}
void print_frequencies(std::vector<int> v)
{
std::sort(v.begin(), v.end());
if (!v.empty())
{
auto prev = v.front();
std::size_t freq = 1;
auto out = [&]{ std::cout << prev << ": " << freq << '\n' ;};
for (std::size_t i = 1; i<v.size(); ++i)
{
if (prev == v[i])
++freq;
else
{
out() ;
prev = v[i];
freq = 1;
}
}
out();
}
}
template <typename container_t>
void print(const container_t& c)
{
std::cout << "{ ";
for (auto& e: c)
std::cout << e << " " ;
std::cout << "}\n";
}
int main()
{
std::vector<int> a ;
print(a);
print_frequencies({});
std::vector<int> b = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 10 };
print(b);
print_frequencies(b);
std::vector<int> c = {1, 2, 1, 3, 1, 3, 5, 1, 5, 1, 5, 1, 4, 1, 4, 1, 8};
print(c);
print_frequencies(c);
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPHZlY3Rvcj4KCnZvaWQgY291bnQoc3RkOjp2ZWN0b3I8aW50PiBhcnIpewogCXN0ZDo6c29ydChhcnIuYmVnaW4oKSwgYXJyLmVuZCgpKTsKICAgIGludCBmcmVxdWVuY3kgPSAxOwoKICAgIGZvciAoaW50IHggPTA7IHggPCBhcnIuc2l6ZSgpLTE7IHggKyspewogICAgICAgIGlmKGFyclt4XT09YXJyW3grMV0pewogICAgICAgICAgICBmcmVxdWVuY3kgKys7CiAgICAgICAgfQogICAgICAgIGVsc2V7CiAgICAgICAgICAgIHN0ZDo6Y291dCA8PCBhcnJbeF0gPDwgIjogIiA8PCBmcmVxdWVuY3kgPDwgc3RkOjplbmRsOwogICAg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