Cod sursa(job #1167622)
| Utilizator | Data | 5 aprilie 2014 16:19:49 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 70 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
#include <unordered_map>
int main()
{
std::ifstream fin("elmaj.in");
std::ofstream fout("elmaj.out");
int n,x;
int max=0, xmax=0;
fin>>n;
std::unordered_map<int, int> m(n*10);
fin>>x;
max=1;
xmax=x;
m[x]=1;
for(int i=1;i<n;i++)
{
fin>>x;
if(m.find(x)==m.end())
{
m[x]=1;
}
else
{
int t = m[x];
if(max<t+1)
{
max = t+1;
xmax=x;
}
m[x]=t+1;
}
}
fout<<xmax<<" "<<max;
return 0;
}
