Cod sursa(job #2133940)
Utilizator | Data | 17 februarie 2018 14:35:31 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <bits/stdc++.h>
using namespace std;
map<int,int> Freq;
int N,max_el;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int main(){
fin >> N;
for (int i = 1; i <= N;i++){
int x;
fin >> x;
Freq[x]++;
if (Freq[x] > Freq[max_el])max_el = x;
}
if (Freq[max_el] >= N/2 +1) fout <<max_el<<" "<<Freq[max_el];
return 0;
}