Cod sursa(job #2133943)

Utilizator cyber_ghSoltan Gheorghe cyber_gh Data 17 februarie 2018 14:38:59
Problema Elementul majoritar Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 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(){
    ios_base::sync_with_stdio(0);
    fin.tie(0);
    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;
}