Cod sursa(job #3289101)

Utilizator Caleb_007Sighiartau Achim Caleb Caleb_007 Data 25 martie 2025 18:09:25
Problema Elementul majoritar Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.98 kb
#define _CRT_SECURE_NO_DEPRECATE
#include <fstream>
#include <cstring>
#include <stdlib.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

ifstream fin("elmaj.in");
ofstream fout("elmaj.out");


int A[1000000];

/*void readNum(int& n, FILE* in)
{ 
    n = 0;
    char c = fgetc(in);
    while (c == ' ' || c=='\n') c = fgetc(in);
    while (c!=EOF && c >= '0' && c <= '9') {
        n = n * 10 + c - 48;
        c = fgetc(in);
    }
}*/

int lmax, emax;

int main()
{
    int n, x;

    //FILE* in = fopen("elmaj.in", "r");

    //readNum(n, in);

    fin >> n;

    for (int i = 0; i < n; i++)
        fin >> A[i];

    sort(A, A + n);

    int l = 1;
    for (int i = 1; i < n; i++)
        if (A[i] == A[i - 1]) {
            l++;
            if (l > lmax) {
                lmax = l;
                emax = A[i];
            }
        }
        else l = 1;

    fout << emax <<" " << lmax;

    return 0;
}