Cod sursa(job #2710654)
| Utilizator | Data | 22 februarie 2021 20:25:56 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
map <int, int> numere;
int n;
int main()
{
fin >> n;
int m = n;
while (m--)
{
int x;
fin >> x;
if (numere.find(x) != numere.end())
numere[x]++;
else
numere.insert(map<int,int>::value_type(x,1));
}
for (auto i = numere.begin(); i != numere.end(); ++i)
if (i->second >= n / 2 + 1)
fout << i -> first << ' ' << i->second;
}
