Нужно получить все комбинации этих связок:
A,A,D A,A,B
A,C,D A,C,B
B,A,D B,A,B
B,C,D B,C,B
uses crt;
type uk = ^P;
P = record
next : uk;
str : string;
end;
var i,n : byte;
t,q : uk;
stroka : string;
procedure division (var q : uk; var s : string);
var n : byte;
s1,s2 : string;
t : uk;
begin
t := q;
n := pos('+',t^.str);
while n <> 0 do
begin
s1 := s[n-1];
s2 := s[n+1];
delete(s,n-2,4);
while t<>Nil do
t := t^.next;
new(t);
t^.next := q;
t^.str := s1 + ',' + s;
q := t;
new(t);
t^.next := q;
t^.str := s2 + ',' + s;
q := t;
s := t^.str;
n := pos('+',t^.str);
end;
end;
Begin
clrscr;
stroka := 'A+B,^C+^D,B,B+C';
n := pos('^',stroka);
while n <> 0 do
begin
stroka[n+1] := chr(ord(stroka[n+1])+32);
delete(stroka,n,1);
n := pos('^',stroka);
end;
q := Nil;
new(t);
t^.next := q;
t^.str := stroka;
q := t;
division(q,stroka);
t := q;
while t<>Nil do
begin
division(t,stroka);
t := t^.next;
end;
while q<> Nil do
begin
writeln(q^.str);
q := q^.next;
end;
readkey;
end.