Cod sursa(job #875551)

Utilizator atatomirTatomir Alex atatomir Data 10 februarie 2013 13:32:03
Problema Sortare prin comparare Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.76 kb
var bufin,bufout:array[1..65000]of byte;
    n,i,max,imax,t,j:longint;
    a:array[1..500001]of longint;
    ok:boolean;

begin
  assign(input,'algsort.in'); reset(input);
  assign(output,'algsort.out'); rewrite(output);
  settextbuf(input,bufin);
  settextbuf(output,bufout);

  readln(n);
  for i := 1 to n do read(a[i]);

  for i := 1 to n-1 do
  begin
    max := a[i];
    imax := i;
    ok := true;

    for j := i+1 to n do
    begin
      if max > a[j] then
      begin
        max := a[j];
        imax := j;
        ok := false;
      end;
    end;

    if ok = false then
    begin
      t := a[i];
      a[i] := max;
      a[imax] := t;
    end;
  end;

  for i := 1 to n do write(a[i]);

  close(input);
  close(output);
end.