Cod sursa(job #2232876)
| Utilizator | Data | 21 august 2018 15:37:06 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
const std::string programName = "elmaj";
std::ifstream f(programName + ".in");
std::ofstream g(programName + ".out");
const int MAX = 5e5;
int main() {
int N;
f >> N;
int ap[MAX + 5] = {0};
while (N--) {
int nr;
f >> nr;
ap[nr]++;
}
int max = 0, Xcopy;
for (int i = 0; i < MAX; ++i)
if (ap[i] > 0)
if (ap[i] > max) {
max = ap[i];
Xcopy = i;
}
g << Xcopy << ' ' << max;
return 0x0;
}
