1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <algorithm>
#include <iterator>
#include <iostream>
int main()
{
long Array[] = {31,42,31,36,43,23,367,377,42, 334,222,644,3434,65,32,42,88};
long SIZE(sizeof(Array) / sizeof(Array[0]));
std::sort(Array, Array + SIZE);
long mostRepeatedValue(0);
long countRepeats(0);
for(long* it(Array); it != Array + SIZE; ++it)
{
std::pair <long* , long*> distance(std::equal_range(Array, Array + SIZE, *it));
if (std::distance(distance.first, distance.second) >= countRepeats)
{
countRepeats = std::distance(distance.first, distance.second);
mostRepeatedValue = *it;
}
}
std::cout << "mostRepeatedValue " << mostRepeatedValue << "\ncountRepeats " << countRepeats << '\n';
return 0;
}
| |