Cod sursa(job #1879907)
| Utilizator | Data | 15 februarie 2017 11:23:24 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int o,p, maj=-1, k;
f>>o;
p=o;
int x[p];
for (int i=0;i<p;i++) {
f>>x[i];
}
for (int i=0;i<p;i++) {
int count=1;
for (int j=i+1;j<p;j++) {
if (x[i]==x[j]) count++;
}
if(maj<count){
maj=count;
k=x[i];
}
}if(k<(p/2+1)) g<<k<<" "<<maj;
}
