Pagini recente » Cod sursa (job #2649966) | Cod sursa (job #1605928) | Cod sursa (job #998520) | Cod sursa (job #1298153) | Cod sursa (job #290232)
Cod sursa(job #290232)
program pascal;
var f,g:Text; ta:ansistring; q,t,aux:char; v:array[97..122] of longint;
s:array[0..1000000] of char;
i,j,n:longint;
procedure citire;
begin
assign(f,'ordine.in'); reset(f);
assign(g,'ordine.out'); rewrite(g);
read(f,ta);
n:=length(ta);
for i:=1 to n do inc(v[ord(ta[i])]);
close(f);
end;
procedure construire;
begin
s[0]:='1';
for i:=1 to n do
begin
aux:='1'; t:='z';
for j:=97 to 122 do
if v[j]<>0 then
begin
q:=chr(j);
if (v[j]>=(n-i+1) div 2+1) and (s[i-1]<>q) then aux:=q
else
if (q<t) and (s[i-1]<>q) then t:=q;
end;
if aux='1' then
begin
write(g,t);
dec(v[ord(t)]);
s[i]:=t;
end
else begin
write(g,aux);
dec(v[ord(aux)]);
s[i]:=aux;
end;
end;
close(g);
end;
begin
citire;
construire;
end.