Cod sursa(job #2264250)
| Utilizator | Data | 19 octombrie 2018 22:13:24 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <iostream>
#include <fstream>
#include <stack>
using namespace std;
stack<int> s;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int n,c[1000001],contor;
int main()
{
in>>n;
for(int i=1;i<=n;++i)
{
in>>c[i];
if(s.size()==0||s.top()==a[i])
s.push(a[i]);
else
if(s.top()!=a[i])
s.pop();
}
for(int i=1;i<=n;i++)
{
if(a[i]==s.top())
contor++;
}
if(contor>n/2)
out<<s.top()<<' '<<contor;
else
out<<-1;
return 0;
}
