题解:
贪心,头尾指针枚举字符串两边,选小的那个,若相等,则往内延伸判断哪边里面的字符更小
参考程序:
var n,l,r,i,t1,t2,bz:longint;
s,s2:ansistring;
c:char;
begin
readln(n);
for i:=1 to n do
begin
readln(c);
s:=s+c;
if (i>1)and(s[i]<>s[i-1]) then bz:=1;
end;
if bz=0 then
begin
for i:=1 to length(s) do
begin
write(s[i]);
if i mod 80=0 then writeln;
end;
exit;
end;
l:=1;
r:=length(s);
while l<r do
begin
if s[l]<s[r] then
begin
s2:=s2+s[l];
inc(l);
end else
if s[r]<s[l] then
begin
s2:=s2+s[r];
dec(r);
end else
begin
t1:=l;
t2:=r;
while s[t1]=s[t2] do
begin
inc(t1);
dec(t2);
end;
if s[t1]<s[t2] then
begin
s2:=s2+s[l];
inc(l);
end else
begin
s2:=s2+s[r];
dec(r);
end;
end;
end;
s2:=s2+s[l];
for i:=1 to length(s2) do
begin
write(s2[i]);
if i mod 80=0 then writeln;
end;
end.