Cod sursa(job #875554)

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

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;

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

    if i <> imax 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.