SORTOWANIE KUBEŁKOWE
program kubelek;
uses crt;
var x: array[1..10] of string;
a: array[1..10] of string;
b: array[1..10] of string;
c: array[1..10] of string;
d: array[1..10] of string;
n,i,e,aa,bb,cc,dd,j,k,l: integer;
literka: string;
begin
clrscr;
writeln('Podaj ile liczb podasz');
readln(n);
writeln('Podaj ',n,' licz ulozonych z literek a, b, c, d');
for i:=1 to n do
begin
readln (x[i]);
end;
writeln;
for e:=4 downto 1 do
begin
aa:=0; bb:=0; cc:=0; dd:=0;
for k:=1 to n do
begin
literka:= copy(x[k],e,1);
if literka='a' then
begin
aa:=aa+1;
a[aa]:=x[k];
end;
if literka='b' then
begin
bb:=bb+1;
b[bb]:=x[k];
end;
if literka='c' then
begin
cc:=cc+1;
c[cc]:=x[k];
end;
if literka='d' then
begin
dd:=dd+1;
d[dd]:=x[k];
end;
end;
i:=1;
for l:=1 to aa do
begin
x[i]:=a[l];
writeln(x[i]);
i:=i+1;
end;
for l:=1 to bb do
begin
x[i]:=b[l];
writeln(x[i]);
i:=i+1;
end;
for l:=1 to cc do
begin
x[i]:=c[l];
writeln(x[i]);
i:=i+1;
end;
for l:=1 to dd do
begin
x[i]:=d[l];
writeln(x[i]);
i:=i+1;
end;
writeln;
end;
for i:=1 to n do writeln(x[i]);
readln;
end.