Cod sursa(job #114956)

Utilizator matemariaescuMaria Mateescu matemariaescu Data 16 decembrie 2007 09:47:41
Problema Litere Scor 40
Compilator fpc Status done
Runda preONI 2008, Runda 2, Clasa a 9-a Marime 0.64 kb
program litere;
var i,n, sch: longint;
    l : array [1..10000] of char;
    fin,fout : text;

procedure bubblesort;
var s : boolean;
    aux : char;
begin
  sch :=0;
  repeat
    s := false;
    for i := 1 to n-1 do
      if l[i]>l[i+1] then
        begin
          sch := sch+1;
          s := true;
          aux := l[i];
          l[i]:=l[i+1];
          l[i+1]:=aux;
        end;
  until s = false;
end;

Begin
  assign(fin,'litere.in'); reset(fin);
  assign(fout,'litere.out'); rewrite(fout);
  readln(fin,n);
  for i := 1 to n do
    read(fin,l[i]);
  BUBBLESORT;
  writeln(fout,sch);
  close(fout);
  close(fin);
End.