主题:Tju1017
各位大虾,下面这个程序为什么过不了?有价值的加30分!
program tju1017;
var a : array[0..20]of longint;
n, a1, a2, i : integer;
procedure sort;
var flag : boolean;
j : integer;
begin
flag:=true;
for i:=1 to n-1 do
begin
for j:=1 to n-i do
if a[j]<a[j+1] then
begin
a[0]:=a[j+1]; a[j+1]:=a[j]; a[j]:=a[0];
flag:=false;
end;
if flag then exit;
end;
end;
begin
repeat
readln(n);
for i:=1 to n do readln(a[i]);
if n=1 then writeln(a[1]);
if n=2 then writeln(abs(a[1]-a[2]));
if (n<>1)and(n<>2) then
begin
sort; a1:=a[1]; a2:=a[2];
for i:=3 to n do
if a1>a2 then a2:=a[i]+a2 else a1:=a[i]+a1;
writeln(abs(a1-a2));
end;
until seekeof;
end.
program tju1017;
var a : array[0..20]of longint;
n, a1, a2, i : integer;
procedure sort;
var flag : boolean;
j : integer;
begin
flag:=true;
for i:=1 to n-1 do
begin
for j:=1 to n-i do
if a[j]<a[j+1] then
begin
a[0]:=a[j+1]; a[j+1]:=a[j]; a[j]:=a[0];
flag:=false;
end;
if flag then exit;
end;
end;
begin
repeat
readln(n);
for i:=1 to n do readln(a[i]);
if n=1 then writeln(a[1]);
if n=2 then writeln(abs(a[1]-a[2]));
if (n<>1)and(n<>2) then
begin
sort; a1:=a[1]; a2:=a[2];
for i:=3 to n do
if a1>a2 then a2:=a[i]+a2 else a1:=a[i]+a1;
writeln(abs(a1-a2));
end;
until seekeof;
end.