Cod sursa(job #793067)
| Utilizator | Data | 1 octombrie 2012 21:32:46 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <fstream>
#include <map>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int main(){
int n;
in >> n;
int i=n, a[n];
for(; i; i--)
in >> a[n-i];
map<int, int> b;
map<int, int>::iterator bi;
for (i = 0; i < n; i++)
if (b.find(a[i]) == b.end())
b[a[i]] = 1;
else
b[a[i]]++;
for (bi=b.begin() ; bi != b.end(); bi++ )
if ((*bi).second > n/2) {
out << (*bi).first << " " << (*bi).second;
return 0;
}
out << -1;
return 0;
}
