Cod sursa(job #2347036)
Utilizator | Data | 18 februarie 2019 12:38:24 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Teme Pregatire ACM Unibuc 2013 | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
register int x[1000005],N,i,j=0,k=0,a;
int main(){
fin >> N;
for(i=1;i<=N;i++) {
fin>>x[i];
if(k==0){
k++;
a=x[i];
}
else if(a==x[i]) k++;
else if(a!=x[i]) k--;
}
fout << a << " ";
for(i=1;i<=N;i++)
if(x[i]==a) j++;
fout << j;
return 0;
}