Cod sursa(job #2438621)
Utilizator | Data | 13 iulie 2019 00:05:11 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.25 kb |
#include <fstream>
std::ifstream fin("elmaj.in");std::ofstream fout("elmaj.out");int n,c,k,i,j, v[1005000];main(){fin>>n;for(;i<n;i++){fin>>v[i];(!k)?c=v[i],k++:(v[i]==c)?k++: k--;}k=0;for(;j<n;j++)if(v[j]==c)k++;(k<n/2+1)?(fout<<-1):(fout<<c<<" "<<k);}