Listing: NUMAR.PAS
var ftmp:Text;
numar,i,j,n,candidat,prezent:Longint;
frecventa:array[0..3,0..255] of Longint;
majoritar:array[0..3] of Byte;
Begin
Assign(input,'B.DAT'); Reset(input);
Assign(ftmp,'TMP.UB1');
while not SeekEof do
begin
Read(n);
Fillchar(frecventa,Sizeof(frecventa),0);
Rewrite(ftmp);
for i:=1 to n
do
begin
Read(numar);
for j:=0 to 3 do
Inc(frecventa[j,(numar shr (8*j))
and 255]);
Writeln(ftmp,numar)
end;
candidat:=0;
for j:=3 downto 0 do
begin
majoritar[j]:=0;
for i:=1 to 255 do
if frecventa[j,majoritar[j]]<
frecventa[j,i]
then majoritar[j]:=i;
candidat:=(candidat shl 8)
or
majoritar[j]
end;
prezent:=0;
Reset(ftmp);
for i:=1 to n do
begin
Read(ftmp,numar);
if numar=candidat then Inc(prezent)
end;
Close(ftmp); Erase(ftmp);
if prezent>n/2
then Writeln(candidat)
else Writeln('Nu exista numar majoritar')
end;
Close(input)
End.