Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MODULE Januar2003;
- FROM InOut IMPORT ReadInt, WriteInt, WriteString, WriteLn;
- FROM Stek IMPORT StekTip, MakeNull, Empty, Push, Top, Pop;
- FROM Info IMPORT InfoTip;
- PROCEDURE f (x,y,z:CARDINAL):CARDINAL;
- BEGIN
- IF z = 0 THEN
- RETURN x
- ELSIF y = 0 THEN
- RETURN 1
- ELSIF x = 0 THEN
- RETURN f(z-1, f(z-1, z, y), y)
- ELSE
- RETURN f(f(x, y, z-1), y-1, z)
- END
- END f;
- PROCEDURE Sf (x,y,z:CARDINAL):CARDINAL;
- VAR
- s:StekTip;
- ok,jos:BOOLEAN;
- el:InfoTip;
- rez,pom:INTEGER;
- BEGIN
- MakeNull(s);
- REPEAT
- WHILE (z<>0) AND (y<>0) DO
- el.x:=x;
- el.y:=y;
- el.z:=z;
- IF x=0 THEN
- el.adr:=1;
- Push(s,el,ok);
- x:=z-1;
- pom:=y;
- y:=z;
- z:=pom
- ELSE
- el.adr:=3;
- Push(s,el,ok);
- z:=z-1
- END
- END;
- IF z=0 THEN
- rez:=x
- ELSIF y=0 THEN
- rez:=1
- END;
- jos:=TRUE;
- WHILE jos AND NOT Empty(s) DO
- Top(s,el,ok);
- Pop(s,ok);
- x:=el.x;
- y:=el.y;
- z:=el.z;
- IF el.adr=1 THEN
- el.adr:=2;
- Push(s,el,ok);
- x:=z-1;
- z:=y;
- y:=rez;
- jos:=FALSE
- ELSIF el.adr=3 THEN
- el.adr:=4;
- Push(s,el,ok);
- x:=rez;
- y:=y-1;
- jos:=FALSE
- END
- END
- UNTIL Empty(s);
- RETURN rez
- END Sf;
- VAR
- x,y,z:INTEGER;
- BEGIN
- WriteString('x= ');
- ReadInt(x);
- WriteString('y= ');
- ReadInt(y);
- WriteString('z= ');
- ReadInt(z);
- WriteLn;
- WriteString('-----f-----');
- WriteLn;
- WriteString('f = ');
- WriteInt(f(x,y,z),1);
- WriteLn;
- WriteString('-----Sf-----');
- WriteLn;
- WriteString('Sf = ');
- WriteInt(Sf(x,y,z),1);
- WriteLn
- END Januar2003.
- InfoTip = RECORD
- x,y,z:INTEGER;
- adr:CARDINAL
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement