Cod sursa(job #728085)

Utilizator vladvaldezVlad Dimulescu vladvaldez Data 28 martie 2012 14:44:43
Problema Cele mai apropiate puncte din plan Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 2.22 kb
type vector=array[1..10]of integer;
var  s,v:vector;
     n,i,h,h1,aux:longint;
     ok:boolean;

procedure qsort(var a :vector);

    procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

    begin
       sort(1,n);
    end;

procedure qsort1(var a :vector);

    procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]>x do
            inc(i);
           while x>a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;

    begin
       sort(2,n);
    end;


begin
assign(input,'2numere.in');reset(input);
assign(output,'2numere.out');rewrite(output);
read(n);
for i:=1 to n do read(v[i]);
for i:=1 to n do read(s[i]);
qsort(v);
qsort(s);
while ok do begin
i:=1;
if s[i]<=v[i] then  begin










{if v[1]=0 then begin
i:=2;
ok:=true;
while v[i]=0 do inc(i);
v[1]:=v[i];
v[i]:=0;
end;






qsort(s);
i:=1;
while (s[i+1]<=v[1])and (i+1<=n) do begin
aux:=s[1];
s[1]:=s[i+1];
s[i+1]:=aux;
inc(i);
end;
qsort1(s);
for i:=1 to n do begin
x:=x*10+v[i];
y:=y*10+s[i];
end;
for i:=1 to n do begin
if ok=false then
write(v[i])
else if v[i]<>0 then write(v[i]);
h:=h*10+v[i];
end;
writeln;
for i:=1 to n do begin
if ok=false then write(s[i])
else if s[i]<>0 then write(s[i]);
h1:=h1*10+s[i];
end;
writeln;
write(h-h1); }
close(output);
end.