P1039 最小差距

var t,i,j,k,x,y,n,temp,kk,kk1,tt,s,yy:longint;a:array[0..11]of longint;
b:array[0..11]of boolean;
begin
for tt:=1 to t do
begin
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]<a[j] then begin temp:=a[i];a[i]:=a[j];a[j]:=temp;end;
if n mod 2=1 then
begin
x:=a[1];
if a[n]=0 then y:=a[n-1] else y:=a[n];
yy:=y;
for j:=2 to n div 2 do x:=x*10+a[j];
for j:=n downto n div 2+1 do
if yy<>a[j] then y:=y*10+a[j];
writeln(abs(x-y));
end;
if n mod 2=0 then
begin
s:=1000000;
if(n=2)and(a[2]=0)then begin writeln(a[1]);continue;end;
for j:=1 to n-1 do
if a[j+1]=0 then break
else
begin
fillchar(b,sizeof(b),true);
x:=a[j];y:=a[j+1];b[j]:=false;b[j+1]:=false;
kk:=1;kk1:=1;
for k:=n downto 1 do
if b[k]then
begin
x:=x*10+a[k];b[k]:=false;inc(kk);
if kk=n div 2 then break;
end;
for k:=1 to n do
if b[k] then
begin
y:=y*10+a[k];b[k]:=false;inc(kk1);
if kk1=n div 2 then break;
end;
if s>abs(x-y) then s:=abs(x-y);
end;
writeln(s);
end;
end;
end.

ID
1039

7

(无)

3685

825

22%

11