Cod sursa(job #1061002)
| Utilizator | Data | 19 decembrie 2013 00:22:57 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Teme Pregatire ACM Unibuc 2013 | Marime | 0.52 kb |
#include<iostream>
#include<fstream>
#include<vector>
#include<unordered_map>
using namespace std;
int V[1000000];
int main(){
ifstream f("elmaj.in");
ofstream o("elmaj.out");
unordered_map<int, int> hash;
int n = 0; f >> n;
for (int i = 0; i < n; i++){
f >> V[i];
if (hash.find(V[i]) != hash.end()){
hash[V[i]]++;
}
else{
hash[V[i]] = 1;
}
}
for (int i = 0; i < n; i++){
if (hash[V[i]] >= n / 2){
o << V[i] << " " << hash[V[i]];
return 0;
}
}
o << -1;
return 0;
}