/ SB域 /

记录详情

Accepted

/usr/bin/ld.bfd: warning: /out/link.res contains output sections; did you forget -T?
# 状态 耗时 内存占用
#1 Accepted 1ms 256.0 KiB
#2 Accepted 3ms 256.0 KiB
#3 Accepted 1ms 256.0 KiB
#4 Accepted 3ms 256.0 KiB
#5 Accepted 1ms 256.0 KiB

代码

var n,i,j,m,t:longint;
    a:array[0..10]of longint;
procedure swap(var a,b:longint);
var t:longint;
begin
t:=a; a:=b; b:=t;
end;
procedure work1;
var s,th:string;
    i,aa,bb:longint;
begin
 th:=''; s:='';
 if a[1]=0 then swap(a[1],a[2]);
 for i:=1 to n div 2+1 do begin
 str(a[i],th);
 s:=s+th;
 end;
 val(s,aa);
 s:='';
 for i:=n downto n div 2+2 do begin
  str(a[i],th);
  s:=s+th;
 end;
 val(s,bb);
 writeln(abs(aa-bb));
 exit;
end;
procedure work2;
var i,j,l,r,min,aa,bb:longint;
    u:array[1..10]of boolean;
    s1,s2,th:string;
begin
 min:=maxlongint;
 for i:=2 to n do begin
  if a[i-1]<>0 then begin
   s1:=''; s2:=''; fillchar(u,sizeof(u),false);
   str(a[i],s1); str(a[i-1],s2);
   u[i]:=true; u[i-1]:=true;
   l:=1; r:=n;
   for j:=1 to (n-2) div 2 do begin
    while u[l] do inc(l);
    while u[r] do dec(r);
    str(a[l],th); s1:=s1+th; u[l]:=true;
    str(a[r],th); s2:=s2+th; u[r]:=true;
   end;
  val(s1,aa); val(s2,bb);
  if abs(aa-bb)<min then min:=abs(aa-bb);
  end;
 end;
 writeln(min);
end;
begin
readln(t);
for m:=1 to t do begin
 readln(n);
 fillchar(a,sizeof(a),0);
 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 swap(a[i],a[j]);
 if n=2 then begin writeln(abs(a[1]-a[2])); continue; end;
 if n mod 2=1 then work1
 else if n mod 2=0 then work2;
end;
end.

信息

递交者
类型
递交
题目
最小差距
题目数据
下载
语言
Pascal
递交时间
2017-08-22 13:40:05
评测时间
2017-08-22 13:40:15
评测机
分数
100
总耗时
11ms
峰值内存
256.0 KiB