Cod sursa(job #964377)
Utilizator | Rusu Alexei RusuAlexei | Data | 20 iunie 2013 19:17:17 |
---|---|---|---|
Problema | Elementul majoritar | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
program elmaj;
var bufin:array[1..100000]of char;
n,i,ans,k,x:longint;
begin
assign(input,'elmaj.in');
reset(input);
settextbuf(input,bufin);
assign(output,'elmaj.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
read(x);
if ans=0 then
begin
ans:=x;
k:=1;
end else
if ans<>x then
begin
dec(k);
if k=0 then ans:=0;
end
else inc(k);
end;
writeln(ans);
close(output);
end.