Эта програма сортирует строку по возростанию длины слов в ней program zada4a;
USES CRT;
var
Stroka:String;
i,j,N,S,K:integer;
mas:array [1..100,1..2] of integer;
Begin
clrscr;
for i:=1 to 100 do
for j:=1 to 2 do
mas[i,j]:=1;
i:=1;j:=1;
read(Stroka);
N:=Length(Stroka)+1;
for i:=1 to N do
if( ((Stroka[i]<>' ') and (i=1)) or ((Stroka[i-1]=' ') and (Stroka[i]<>' ')) ) then
Begin
mas[j,1]:=i;
while( (Stroka[i]<>' ') and (i<>N) ) do
Begin
inc(mas[j,2]);
inc(i);
End;
inc(j);
End;
S:=j-1;
for i:=1 to S do
for j:=1 to S-i do
if(mas[j,2]>mas[j+1,2]) then
Begin
K:=mas[j,2];
mas[j,2]:=mas[j+1,2];
mas[j+1,2]:=K;
K:=mas[j,1];
mas[j,1]:=mas[j+1,1];
mas[j+1,1]:=K;
End;
for i:=1 to S do
Begin
j:=mas[i,1];
while( (Stroka[j]<>' ') and (j<>N) ) do
Begin
write(Stroka[j]);
inc(j);
End;
write(' ');
End;
readkey;
End.