Pagini recente » Cod sursa (job #1449163) | Cod sursa (job #673294) | Cod sursa (job #2865772) | Cod sursa (job #2318182) | Cod sursa (job #119829)
Cod sursa(job #119829)
const fi='ordine.in';
fo='ordine.out';
var
f:text;
A:array[1..64060] of char;
Ap:Array['a'..'z'] of longint;
i,u,k:longint;
c,ch:char;
Begin
for c:='a' to 'z' do
Ap[c]:=0;
assign(f,fi);reset(f);
k:=0;
while Not eof(f) do
begin
read(f,c);
k:=k+1;
Ap[c]:=Ap[c]+1;
end;
close(f);
u:=0;
while u<k do
begin
c:='a';
while Ap[c]=0 do
c:=succ(c);
u:=u+1;
ch:=succ(c);
while (ch<='z') and (Ap[ch]<Trunc((k-u+1)/2)+1) do
ch:=succ(ch);
if ch in ['a'..'z'] then
begin
A[u]:=ch;
Ap[ch]:=Ap[ch]-1;
end
else begin
while Ap[c]=0 do
c:=succ(c);
if c=A[u-1] then begin
ch:=succ(c);
while (Ap[ch]=0) and (ch<'z')do
ch:=succ(ch);
A[u]:=ch;
Ap[ch]:=Ap[ch]-1;
end
else begin
A[u]:=c;
Ap[c]:=Ap[c]-1;
end;
end;
end;
assign(f,fo);rewrite(f);
i:=1;
while A[i]<>#0 do begin
write(f,A[i]);
i:=i+1;
end;
close(f);
End.