Skip to content

Instantly share code, notes, and snippets.

@brun0xff
Created January 5, 2017 03:08
Show Gist options
  • Save brun0xff/1ed0b89a3b2fa3f9004245d892354a5c to your computer and use it in GitHub Desktop.
Save brun0xff/1ed0b89a3b2fa3f9004245d892354a5c to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define endl '\n'
#define DV(value) cout << "[" << value << "]";
#define DPI(p) cout << "[" << p.first << "," << p.second << "]";
#define MAX 10000
using namespace std;
typedef pair<int,int> pii;
struct Comp {
// important: we need two overloads, because the comparison
// needs to be done both ways to check for equality
bool operator()(pii p, int s) const
{ return p.first < s; }
bool operator()(int s, pii p) const
{ return s < p.first; }
};
struct cmp
{
bool operator() ( const pii &a, const pii &b) const {
if(a.second > b.second) return true;
else if(a.second < b.second) return false;
else return a.first < b.first;
}
};
int main()
{
int N,M;
while(cin >> N >> M and N != 0 and M != 0)
{
unordered_map<int,int> aparicoes;
for(int i = 0; i < N;i++)
{
for(int j = 0; j < M;j++)
{
int id;
cin >> id;
auto it = aparicoes.find(id);
if(it != aparicoes.end())
aparicoes[id] = aparicoes[id] + 1;
else
aparicoes[id] = 0;
}
}
set<pii,cmp> apar_ord;
for(auto item : aparicoes)
{
apar_ord.insert( item );
}
int value = apar_ord.begin()->second;
auto it = apar_ord.begin();
while(it != apar_ord.end() and value == it->second) it++;
value = it->second;
while(it != apar_ord.end() and value == it->second)
{
cout << it->first << " ";
it++;
}
cout << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment