Есть одна гипотеза. Попробуйте такой вариант:
Код:
Uses CRT;
Var
s:string;
Function RAR(s:string):string;
var
s1,s2: string;
i,j,k: integer;
begin
s1:='';
i:=1;
while i<=length(s)-1 do
begin
if s[i]=s[i+1] then
begin
k:=1;
j:=i;
repeat
k:=k+1;
j:=j+1;
until s[j]<>s[j+1];
str(k,s2);
s1:=s1+s[i]+'('+s2+')';
i:=i+k;
end
else
begin
s1:=s1+s[i];
i:=i+1;
end;
end;
if s[length(s)]<>s[length(s) - 1] then s1:=s1+s[length(s)];
RAR:=s1;
end;
Begin
write('Enter the string: ');
Readln(s);
write('Compressed string: ', RAR(s));
ReadKey
End.