拼数pascal程序
题意
将一些是接起来,找出接的最大的数
分析
这题其实就是最大整数。做的时候,我们可以先把数字符串排序,从小到大,再一个一个接起来
var
n,i,x,j:longint;
t:string;
s:array[0..20]of string;
procedure kp(l,r:longint);
var
i,j:longint;
mid:string;
begin
if l>=r then exit;
i:=l;j:=r;mid:=s[(l+r) div 2];
repeat
while s[i]>mid do inc(i);
while s[j]<mid do dec(j);
if i<=j then
begin
s[0]:=s[i];s[i]:=s[j];s[j]:=s[0];
inc(i);dec(j);
end;
until i>j;
kp(l,j);
kp(i,r);
end;
begin
readln(n);
for i:=1 to n do
begin
read(x);
str(x,s[i]);
end;
for i:=1 to n-1 do
begin
for j:=i+1 to n do
begin
if s[i]+s[j]<s[j]+s[i] then
begin
t:=s[i];
s[i]:=s[j];
s[j]:=t;
end;
end;
end;
for i:=1 to n do
write(s[i]);
end.