Cod sursa(job #1074655)
Utilizator | Data | 7 ianuarie 2014 20:25:44 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <cstdio>
using namespace std;
const int VMAX = 1000000;
int main() {
int n, i, j, x, v[VMAX];
freopen("elmaj.in", "r", stdin);
freopen("elmaj.out", "w", stoud);
scanf("%d", &n);
for (i = 0; i < n; ++i) {
scanf("%d", &x);
for(j = i; j > 0 && v[j-1] > x; --j) {
v[j] = v[j-1];
}
v[j] = x;
}
printf("%d", v[n/2]);
return 0;
}