for g:=1 to 26 do
Begin
If pos(')',s)=(pos('(',s)-1) then
Begin
s9:=copy(s,1,pos(')',s)-1);
s8:=copy(s,pos(')',s)+1,length(s)-pos('(',s)+1);
s10:=s8;
delete(s,1,Length(s8)+length(s9)+1);
for ch5 := 'A' to 'Z' do
begin
if pos(ch5, s9) > 0 then
prs1 := prs1 + ch5;
end;
s9:=prs1;
writeln(s9);
For m:=1 to (length(s9)-1) do
Begin
S8:=s8+'+'+s8;
End;
Insert(s9[1],s8,1);
For m:=1 to (length(s9)-1) do
Begin
Insert(s9[1+m],s8,pos(s9[1],s8)+length(s10)+2);
End;
s:=s+s8;
End;
If pos(per[g],s)=(pos('(',s)-1) then
begin
If pos('+',s)>pos('(',s) then
if pos('+',s)<pos(')',s) then {A*(A+B) }
begin
insert(per[g],s,pos('+',s)+1);
delete(s,pos('(',s)+length(s),1);
{ delete(s,pos('(',s),1);
delete(s,pos(')',s),1); }
End;
If pos(per[g],s)=(pos('(',s)-1) then {A*(A*B)}
begin
delete(s,pos('(',s),1);
delete(s,pos('(',s)+length(s),1);
End;
End;
End;
Writeln(s);
Мне надо раскрыть скобки в выражении, я вошел в тупик в таком случае, когда (A+C)(A+B) , в первом цткле я такое выражение преобразую в A(A+B)+C(A+B), во втором цикле должно выйти AA+AB+CA+CB, а выходит AA+AB+CA+B, не подскажете в чем ошибка или есть какой-нибудь другой способ.