Listing LIVRARI.PAS program orders; const ni='orders.in'; no='orders.out'; nmax=26; tmax=200; var f:Text; buffer:array [1..60000] of Char; nr:array ['a'..'z'] of Integer; car:array [1..nmax] of Char; cate:array [1..nmax] of Integer; out:array [1..tmax] of Char; ch:Char; i,l,s:Integer; procedure load; begin for ch:='a' to 'z' do nr[ch]:=0; Assign(f,ni); Reset(f); while not Seekeoln(f) do begin Read(f,ch); nr[ch]:=nr[ch]+1; end; Close(f) end; procedure preprocess; begin l:=0; s:=0; for ch:='a' to 'z' do if nr[ch]>0 then begin l:=l+1; car[l]:=ch; cate[l]:=nr[ch]; s:=s+cate[l] end end; procedure scrie; begin for i:=1 to s do Write(f,out[i]); Writeln(f) end; procedure rec(k:Integer); var i:Integer; begin if k>s then scrie else for i:=1 to l do if cate[i]>0 then begin out[k]:=car[i]; cate[i]:=cate[i]-1; rec(k+1); cate[i]:=cate[i]+1 end end; procedure bkt; begin Assign(f,no); Settextbuf(f,buffer); Rewrite(f); rec(1); Close(f) end; Begin load; preprocess; bkt End. [cuprins] |