Cod sursa(job #1060359)

Utilizator miu_mik93FMI - Paduraru Miruna miu_mik93 Data 17 decembrie 2013 21:58:16
Problema Elementul majoritar Scor 0
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 1.05 kb
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
//#include <unordered_map>
#define NMAX 1000001
#define ERROR 0.0001
 
 
  
int main()
{
    FILE *f = fopen ("elmaj.in", "r");
    FILE *g = fopen ("elmaj.out", "w");
     
    unordered_map<int, int> hashs;
    int x, n;
     
    fscanf (f, "%d", &n);
    for (int i = 0; i < n; i++)
    {
        fscanf (f, "%d", &x);
        hashs[x]++;
    }
    
    int found = 0;
    for(unordered_map<int, int>::iterator it = hashs.begin(); it != hashs.end() && !found; it++)
    {
        if ( it->second > n / 2 )
        {
            fprintf (g, "%d %d", it->first, it->second);
            found = 1;
        }
    }
 
    if ( !found )
        fprintf (g, "-1");
 
    fclose(f);
    fclose(g);
    return 0;
}