#include <algorithm>
#include <map>
#include <iterator>
#include <iostream>
int main()
{
int a[] = {2,2,3,4,5,6,5,4,3,2,3,4,5,4,3,3,3,3,4,5,4,2,3,4,5,4};
size_t sz = sizeof(a)/sizeof(a[0]);
std::map<int, size_t> m;
/*
std::for_each(a, a+sz, [&m](int v) {
m[v]++;
});
*/
std::copy(a, a+sz, std::inserter(m, m.end()));
auto ptrMax = std::max_element(m.begin(), m.end(), [&m](const std::map<int, size_t>::value_type & v1, const std::map<int, size_t>::value_type & v2) {
return v1.second < v2.second;
});
std::cout << ptrMax->first << ": " << ptrMax->second;
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPGl0ZXJhdG9yPgojaW5jbHVkZSA8aW9zdHJlYW0+CgppbnQgbWFpbigpIAp7CglpbnQgYVtdID0gezIsMiwzLDQsNSw2LDUsNCwzLDIsMyw0LDUsNCwzLDMsMywzLDQsNSw0LDIsMyw0LDUsNH07CglzaXplX3Qgc3ogPSBzaXplb2YoYSkvc2l6ZW9mKGFbMF0pOwoKCXN0ZDo6bWFwPGludCwgc2l6ZV90PiBtOwovKgoJc3RkOjpmb3JfZWFjaChhLCBhK3N6LCBbJm1dKGludCB2KSB7CgkJbVt2XSsrOwoJfSk7CgkqLwoJCglzdGQ6OmNvcHkoYSwgYStzeiwgc3RkOjppbnNlcnRlcihtLCBtLmVuZCgpKSk7CgoJYXV0byBwdHJNYXggPSBzdGQ6Om1heF9lbGVtZW50KG0uYmVnaW4oKSwgbS5lbmQoKSwgWyZtXShjb25zdCBzdGQ6Om1hcDxpbnQsIHNpemVfdD46OnZhbHVlX3R5cGUgJiB2MSwgY29uc3Qgc3RkOjptYXA8aW50LCBzaXplX3Q+Ojp2YWx1ZV90eXBlICYgdjIpIHsKCQlyZXR1cm4gdjEuc2Vjb25kIDwgdjIuc2Vjb25kOwoJfSk7CgoJc3RkOjpjb3V0IDw8IHB0ck1heC0+Zmlyc3QgPDwgIjogIiA8PCBwdHJNYXgtPnNlY29uZDsKCQoKfQ==
In file included from /usr/include/c++/4.9/algorithm:61:0,
from prog.cpp:1:
/usr/include/c++/4.9/bits/stl_algobase.h: In instantiation of 'static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = int*; _OI = std::insert_iterator<std::map<int, unsigned int> >]':
/usr/include/c++/4.9/bits/stl_algobase.h:396:70: required from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = int*; _OI = std::insert_iterator<std::map<int, unsigned int> >]'
/usr/include/c++/4.9/bits/stl_algobase.h:434:38: required from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = int*; _OI = std::insert_iterator<std::map<int, unsigned int> >]'
/usr/include/c++/4.9/bits/stl_algobase.h:466:17: required from '_OI std::copy(_II, _II, _OI) [with _II = int*; _OI = std::insert_iterator<std::map<int, unsigned int> >]'
prog.cpp:18:46: required from here
/usr/include/c++/4.9/bits/stl_algobase.h:336:18: error: no match for 'operator=' (operand types are 'std::insert_iterator<std::map<int, unsigned int> >' and 'int')
*__result = *__first;
^
/usr/include/c++/4.9/bits/stl_algobase.h:336:18: note: candidates are:
In file included from /usr/include/c++/4.9/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.9/algorithm:61,
from prog.cpp:1:
/usr/include/c++/4.9/bits/stl_iterator.h:639:7: note: std::insert_iterator<_Container>& std::insert_iterator<_Container>::operator=(const typename _Container::value_type&) [with _Container = std::map<int, unsigned int>; typename _Container::value_type = std::pair<const int, unsigned int>]
operator=(const typename _Container::value_type& __value)
^
/usr/include/c++/4.9/bits/stl_iterator.h:639:7: note: no known conversion for argument 1 from 'int' to 'const value_type& {aka const std::pair<const int, unsigned int>&}'
/usr/include/c++/4.9/bits/stl_iterator.h:647:7: note: std::insert_iterator<_Container>& std::insert_iterator<_Container>::operator=(typename _Container::value_type&&) [with _Container = std::map<int, unsigned int>; typename _Container::value_type = std::pair<const int, unsigned int>]
operator=(typename _Container::value_type&& __value)
^
/usr/include/c++/4.9/bits/stl_iterator.h:647:7: note: no known conversion for argument 1 from 'int' to 'std::map<int, unsigned int>::value_type&& {aka std::pair<const int, unsigned int>&&}'
/usr/include/c++/4.9/bits/stl_iterator.h:588:11: note: std::insert_iterator<std::map<int, unsigned int> >& std::insert_iterator<std::map<int, unsigned int> >::operator=(const std::insert_iterator<std::map<int, unsigned int> >&)
class insert_iterator
^
/usr/include/c++/4.9/bits/stl_iterator.h:588:11: note: no known conversion for argument 1 from 'int' to 'const std::insert_iterator<std::map<int, unsigned int> >&'
/usr/include/c++/4.9/bits/stl_iterator.h:588:11: note: std::insert_iterator<std::map<int, unsigned int> >& std::insert_iterator<std::map<int, unsigned int> >::operator=(std::insert_iterator<std::map<int, unsigned int> >&&)
/usr/include/c++/4.9/bits/stl_iterator.h:588:11: note: no known conversion for argument 1 from 'int' to 'std::insert_iterator<std::map<int, unsigned int> >&&'