Cod sursa(job #1409954)

Utilizator casianos1996Marc Casian Nicolae casianos1996 Data 30 martie 2015 19:49:11
Problema Elementul majoritar Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 0.59 kb
program elmaj;
var     nr,x,n,m,c,i,j:longint;
begin
  assign(input,'elmaj.in'); reset(input);
  assign(output,'elmaj.out'); rewrite(output);
  readln(n);
  m:=-1; c:=1;
  for i:=1 to n do
    begin
      read(x);
      if x=m then inc(c)
      else
        begin
          dec(c);
          if c=0 then
            begin
              m:=x;
              c:=1;
            end;
        end;
    end;
  close(input);
  reset(input);
  readln(n);
  nr:=0;
  for i:=1 to n do
    begin
      read(x);
      if x=m then inc(nr);
    end;
  writeln(m,' ',nr);
  close(output);
end.