Cod sursa(job #2187001)

Utilizator OldpugAlex Ionescu Oldpug Data 26 martie 2018 09:37:40
Problema Elementul majoritar Scor 0
Compilator cpp Status done
Runda bpc10 Marime 0.43 kb
#include <fstream>
#include <unordered_map>
#include <cstdint>

int main() {
  std::ifstream in{"elmaj.in"};
  std::ofstream out{"elmaj.out"};

  std::unordered_map<int32_t, int32_t> map;

  int32_t n{};
  in >> n;

  int32_t i{};
  while (in >> i)
    ++map[i];

  for (auto elem : map) {
    auto count{elem->second};

    if (count > n / 2)
      out << elem->first << ' ' << count;
    else
      out << -1;
  }
}