Mai intai trebuie sa te autentifici.
Cod sursa(job #3285653)
| Utilizator | Data | 13 martie 2025 12:07:59 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fcin("elmaj.in");
ofstream fout("elmaj.out");
int n, v[1000001];
void elmaj(int n, int v[])
{
int i=1;
int found=0;
while (i<n)
{
cout<<"A";
int j=i;
while (v[j+1]==v[i] && j<n)
j++;
if (j-i+1>=n/2+1)
{
fout<<v[i]<<" "<<j-i+1;
found=1;
break;
}
i=j+1;
}
if (!found)
fout<<-1;
}
int main()
{
fcin>>n;
for (int i=1; i<=n; i++)
{
fcin>>v[i];
}
sort(v+1, v+n+1);
elmaj(n, v);
}
