给定一个非空的数字数组。显示此数组中最常见的数量。
#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;
}
如果是二维数组,我可以重写这样的程序吗?我该怎么办?