Pagini recente » Cod sursa (job #861621) | Cod sursa (job #5712) | Cod sursa (job #24465) | Cod sursa (job #1662570) | Cod sursa (job #115508)
Cod sursa(job #115508)
type sir=array[1..10000] of char;
var x:sir;
n,i,nr:integer;
f,g:text;
aux:char;
function ordo(x:sir; a:integer):boolean;
var i:integer;
begin
ordo:=true;
for i:=1 to a-1 do if x[i]>x[i+1] then
begin
ordo:=false;
exit;
end;
end;
begin
assign(f,'litere.in'); reset(f);
assign(g,'litere.out'); rewrite(G);
readln(f,n); nr:=0;
for i:=1 to n do read(f,x[i]);
while not ordo(x,n) do
for i:=1 to n-1 do
if x[i]>x[i+1] then
begin
aux:=x[i];
x[i]:=x[i+1];
x[i+1]:=aux;
inc(nr);
end;
writeln(g,nr);
close(g);
end.