Listing SACI.PAS
Program
typeref=^inr;
inr=record
dr,tata:ref;
a,b,c:Integer
end;
vara,b,c,pz:Integer;
f:Text;
final,temp,rad,poz,caut:ref;
m:array[1..300,1..3] of Integer;
functionminim(a,b,c,pz:Integer):Integer;
var t:Integer;
begin
if a>b then begin t:=a; a:=b; b:=t end;
if a>c then begin t:=a; a:=c; c:=t end;
if b>c then begin t:=c; c:=b; b:=t end;
case pz of
1 : minim:=a;
2 : minim:=b;
3 : minim:=c
end
end;
procedureinitializare;
begin
New(rad); New(temp);
rad^.dr:=temp;
temp^.dr:=nil; temp^.tata:=nil;
temp^.a:=minim(a,b,c,1);
temp^.b:=minim(a,b,c,2);
temp^.c:=minim(a,b,c,3);
poz:=rad; final:=temp
end;
procedurecitire;
begin
Assign(f,'SACI.IN');
Reset(f);
Readln(f,a,b,c);
Close(f)
end;
function verif:Boolean;
var test:Boolean;
begin
test:=false;
if final^.a=final^.b
then
begin
test:=true; m[1,1]:=0;
m[1,2]:=b+a; m[1,3]:=c; pz:=1
end;
if final^.a=final^.c
then
begin
test:=true; m[1,1]:=0;
m[1,2]:=b; m[1,3]:=c+a; pz:=1
end;
if final^.b=final^.c
then
begin
test:=true; m[1,1]:=a;
m[1,2]:=b+b; m[1,3]:=0; pz:=1
end;
verif:=test
end;
procedurecautare;
label 10;
var test:Boolean;
begin
if verif then goto 10;
repeat
poz:=poz^.dr;
a:=minim(poz^.a+poz^.a,
poz^.b-poz^.a,poz^.c,1);
b:=minim(poz^.a+poz^.a,
poz^.b-poz^.a,poz^.c,2);
c:=minim(poz^.a+poz^.a,
poz^.b-poz^.a,poz^.c,3);
test:=true; temp:=rad;
repeat
temp:=temp^.dr;
if (temp^.a=a) and (temp^.b=b) and
(temp^.c=c)
then test:=false
until (temp^.dr=nil) or not test;
if test
then
begin
New(temp); temp^.tata:=poz;
temp^.a:=a; temp^.b:=b; temp^.c:=c;
temp^.dr:=nil; final^.dr:=temp;
final:=temp;
if verif then goto 10
end;
a:=minim(poz^.a+poz^.a,
poz^.b,poz^.c-poz^.a,1);
b:=minim(poz^.a+poz^.a,
poz^.b,poz^.c-poz^.a,2);
c:=minim(poz^.a+poz^.a,
poz^.b,poz^.c-poz^.a,3);
test:=true; temp:=rad;
repeat
temp:=temp^.dr;
if (temp^.a=a) and (temp^.b=b) and
(temp^.c=c)
then test:=false
until (temp^.dr=nil) or not test;
if test
then
begin
New(temp); temp^.tata:=poz;
temp^.a:=a; temp^.b:=b; temp^.c:=c;
temp^.dr:=nil; final^.dr:=temp;
final:=temp;
if verif then goto 10
end;
a:=minim(poz^.a,poz^.b+poz^.b,
poz^.c-poz^.b,1);
b:=minim(poz^.a,poz^.b+poz^.b,
poz^.c-poz^.b,2);
c:=minim(poz^.a,poz^.b+poz^.b,
poz^.c-poz^.b,3);
test:=true;
temp:=rad;
repeat
temp:=temp^.dr;
if (temp^.a=a) and (temp^.b=b) and
(temp^.c=c)
then test:=false
until (temp^.dr=nil) or not test;
if test
then
begin
New(temp); temp^.tata:=poz;
temp^.a:=a; temp^.b:=b; temp^.c:=c;
temp^.dr:=nil; final^.dr:=temp;
final:=temp;
if verif then goto 10
end
until false;
10:
end;
proceduresfarsit;
begin
while final<>nil do
begin
pz:=pz+1; m[pz,1]:=final^.a;
m[pz,2]:=final^.b; m[pz,3]:=final^.c;
final:=final^.tata
end
end;
function testare(var a,b,c:Integer;
a1,b1,c1:Integer; m1,m2:Integer):Boolean;
var test:Boolean;
begin
test:=true;
if a<>a1 then test:=false;
if b1<>b+b then test:=false;
if c1<>c-b then test:=false;
if test
then
begin
a:=a1; b:=b1; c:=c1;
Writeln(f,m1,' ',m2)
end;
testare:=test
end;
function ct(var a,b,c:Integer;
a1,b1,c1,m1,m2:Integer):Boolean;
var test:Boolean;
begin
test:=false;
if testare(a,b,c,a1,b1,c1,m1,m2)
then test:=true
else
if testare(a,b,c,b1,a1,c1,m1,m2)
then test:=true
else
if testare(a,b,c,c1,a1,b1,m1,m2)
then test:=true
else
if testare(a,b,c,a1,c1,b1,m1,m2)
then test:=true
else
if testare(a,b,c,b1,c1,a1,m1,m2)
then test:=true
else
if testare(a,b,c,c1,b1,a1,m1,m2)
then test:=true;
ct:=test
end;
proceduretiparire;
var i:Word;
begin
Assign(f,'SACI.IN'); Reset(f); Readln(f,a,b,c);
Close(f);
Assign(f,'SACI.OUT'); Rewrite(f);
Writeln(f,pz-1);
for i:=pz-1 downto 1 do
begin
if ct(a,b,c,m[i,1],m[i,2],m[i,3],3,2)
then
else
if ct(a,c,b,m[i,1],m[i,2],m[i,3],2,3)
then
else if ct(b,a,c,m[i,1],m[i,2],m[i,3],3,1)
then
else
if ct(b,c,a,m[i,1],m[i,2],m[i,3],1,3)
then
else
if ct(c,a,b,m[i,1],m[i,2],m[i,3],2,1)
then
else
if ct(c,b,a,m[i,1],m[i,2],m[i,3],1,2)
then
end;
Close(f)
end;
procedurestergere;
begin
temp:=rad;
while temp<>nil do
begin
final:=temp; temp:=temp^.dr; Dispose(final)
end
end;
Begin
citire;
initializare;
cautare;
sfarsit;
tiparire;
stergere
End.