Răspuns:
program reordonareCifre;
var num, i, j, cif, m:integer;
vf:array[0..9]of integer;
begin
read(num);
if num=0 then vf[0]:=1
else
begin
while num<>0 do
begin
cif:=num mod 10;
vf[cif]:=vf[cif]+1;
num:=num div 10;
end;
end;
m:=0;
if vf[0]>0 then
begin
i:=1;
while vf[i]=0 do i:=i+1;
m:=i;
vf[i]:=vf[i]-1;
end;
for i:=0 to 9 do
begin
if vf[i]>0 then
begin
for j:=1 to vf[i] do
begin
m:=m*10+i;
end;
end;
end;
writeln(m);
end.
Explicație:
vector de frecvență vf