Cod sursa(job #136391)

Utilizator you_reheroMihai Gojinetchi you_rehero Data 15 februarie 2008 15:23:18
Problema Secv Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1 kb
var fi,fo:text;
    n,i,j,ct:integer;
    nr,x,s:array[1..5000]of longint;
function part(st,dr:integer):integer;
var i,j,s:integer;
    aux:longint;
begin
  i:=st; j:=dr; s:=-1;
  while i<j do
    begin
      if nr[i]>nr[j] then
        begin
          aux:=nr[i];
          nr[i]:=nr[j];
          nr[j]:=aux;
          s:=-s;
        end;
      if s=1 then inc(i)
             else dec(j);
    end;
  part:=i;
end;
procedure qsort(st,dr:integer);
var p:integer;
begin
  if st<dr then
    begin
      p:=part(st,dr);
      qsort(st,p-1);
      qsort(p+1,dr);
    end;
end;
begin
  assign(fi,'secv.in'); reset(fi);
  assign(fo,'secv.out'); rewrite(fo);
  read(fi,n);
  for i:=1 to n do
    begin
      read(fi,nr[i]);
      s[i]:=nr[i];
    end;
  qsort(1,n);
  ct:=1;
  x[ct]:=nr[1];
  for i:=2 to n do
    if nr[i]<>nr[i-1] then
      begin
        inc(ct);
        x[ct]:=nr[i];
      end;
  for i:=1 to ct do
    write(fo,x[i],' ');
  close(fi);
  close(fo);
end.