用map,注意范围是2^24,所以int可以。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
map<int, int> mp;
int main()
{
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int M = 0, N = 0;
scanf("%d %d", &M, &N);
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
int a;
scanf("%d", &a);;
mp[a]++;
}
}
for (map<int,int>::iterator it = mp.begin(); it != mp.end(); it++)
{
if (it->second > M*N/2)
printf("%d", it->first);
}
return 0;
}