Given a non-empty array of numbers. Display the number of the most common in this array.
#include <iostream>
#include <map>
#include <algorithm>
#include <clocale>
#include <iterator>
int main()
{
setlocale(LC_ALL, "");
const int size = 5;
int array[size];
for (int i = 0; i < size; i++)
std::cin >> array[i];
std::map<int, int> map;
for (int i = 0; i < size; i++)
map[array[i]] = std::count(std::begin(array), std::end(array), array[i]);
std::cout<< "The most common element: " << map.begin()->first << std::endl;
std::sort(std::begin(array), std::end(array));
std::cout << "Sorting array: \n";
std::copy(std::begin(array), std::end(array), std::ostream_iterator<int>(std::cout, " "));
std::cout<< std::endl;
}
Can I rewrite such program in case two-dimensional array? And how i can it do?