type PVyraz = ^TVyraz; TVyraz = record operace: char; cislo: integer; L,P: PVyraz end; function Vyraz( operace: char; cislo: integer; L,P: PVyraz ): PVyraz; var n: PVyraz; begin new ( n ); n^.operace := operace; n^.cislo := cislo; n^.L := L; n^.P := P; Vyraz := n end; function Hodnota( v: PVyraz ): integer; begin if v^.operace = 'x' then Hodnota := v^.cislo else if v^.operace = '+' then Hodnota := Hodnota( v^.L ) + Hodnota( v^.P ) else if v^.operace = '-' then Hodnota := Hodnota( v^.L ) - Hodnota( v^.P ) else if v^.operace = '*' then Hodnota := Hodnota( v^.L ) * Hodnota( v^.P ) else if v^.operace = '/' then Hodnota := Hodnota( v^.L ) div Hodnota( v^.P ) else write end; var v: PVyraz; begin v := Vyraz( '+', 0, Vyraz( 'x', 1, NIL,NIL ), Vyraz( '*', 0, Vyraz( 'x', 5, NIL, NIL ), Vyraz( 'x', 7, NIL, NIL ) ) ); writeln( Hodnota( v ) ) end. type PPrvek = ^TPrvek; TPrvek = record x: integer; Dalsi: PPrvek; end; function Prvek( x: integer; Dalsi: PPrvek ): PPrvek; var n: PPrvek; begin new( n ); n^.x := x; n^.Dalsi := Dalsi; Prvek := n end; var zac, p: PPrvek; begin zac := Prvek( 10, Prvek( 20, Prvek( 30, Prvek( 40, Prvek( 50, Prvek( 60, NIL )))))); p := zac; while p<>NIL do begin write( p^.x,' ' ); p := p^.Dalsi end end. const N = 10; a: array[1..N] of integer = (10, 35, 18, 29, 46, 1, 7, 3, 5, 9 ); var pocet: integer; function LzeVybrat( soucet: integer; od: integer ): boolean; begin if soucet = 0 then begin LzeVybrat := TRUE; pocet := pocet + 1 end else if od > N then LzeVybrat := FALSE else begin LzeVybrat := FALSE; if LzeVybrat( soucet, od+1 ) then LzeVybrat := TRUE; if LzeVybrat( soucet-a[od], od+1 ) then LzeVybrat := TRUE end end; begin pocet := 0; writeln( LzeVybrat( 100,1 ) ); writeln( pocet,' moznosti' ) end. const N = 10; a: array[1..N] of integer = (10, 35, 18, 29, 46, 1, 7, 3, 5, 9 ); function LzeVybrat( soucet: integer; od: integer ): boolean; begin if soucet = 0 then LzeVybrat := TRUE else if od > N then LzeVybrat := FALSE else if LzeVybrat( soucet, od+1 ) then LzeVybrat := TRUE else if LzeVybrat( soucet-a[od], od+1 ) then LzeVybrat := TRUE else LzeVybrat := FALSE end; begin writeln( LzeVybrat( 100,1 ) ) end. procedure VypisVsechnyKombinace( zceho: string; od: integer; tisk: string ); var i: integer; begin { if zceho='' then {} if length( tisk )=3 then writeln( tisk ) else for i:=od to length(zceho) do VypisVsechnyKombinace(zceho, i+1, tisk + zceho[i] ) end; begin writeln; VypisVsechnyKombinace( 'abcdefg', 1, '' ); end. procedure VypisVsechnyVariace( zceho: string; tisk: string ); var i: integer; begin { if zceho='' then {} if length( tisk )=3 then writeln( tisk ) else for i:=1 to length(zceho) do VypisVsechnyVariace( copy(zceho,1,i-1) + copy(zceho,i+1,length(zceho)-i), tisk + zceho[i] ) end; begin writeln; VypisVsechnyVariace( 'abcd','' ); end. procedure VypisVsechnyPermutace( zceho: string; tisk: string ); var i: integer; begin if zceho='' then writeln( tisk ) else for i:=1 to length(zceho) do VypisVsechnyPermutace( copy(zceho,1,i-1) + copy(zceho,i+1,length(zceho)-i), tisk + zceho[i] ) end; begin VypisVsechnyPermutace( 'abcd','PERMUTACE: ' ); end. procedure VypisVsechnaKladnaCislaMensiNeboRovnaN( N: integer ); begin if N > 0 then begin writeln( N ); VypisVsechnaKladnaCislaMensiNeboRovnaN( N-1 ); end end; begin VypisVsechnaKladnaCislaMensiNeboRovnaN( 10 ) end. function Hodnota( s: string ): integer; var i, min, imin, p, x, zavorky: integer; begin { najit operaci s nejmensi prioritou: } min := maxint; zavorky := 0; for i:=1 to length(s) do begin if (s[i]='(') then zavorky := zavorky + 10; if (s[i]=')') then zavorky := zavorky - 10; if (s[i]='+') or (s[i]='-') or (s[i]='*') or (s[i]='/') then begin if (s[i]='+') or (s[i]='-') then p := 1 + zavorky; if (s[i]='*') or (s[i]='/') then p := 2 + zavorky; if p <= min then begin min := p; imin := i end end end; if min < maxint then if min > 10 then Hodnota := Hodnota( copy(s,2,length(s)-2 ) ) else begin if s[imin]='+' then Hodnota := Hodnota( copy(s,1,imin-1) ) + Hodnota( copy(s,imin+1, length(s)-imin ) ) else if s[imin]='-' then Hodnota := Hodnota( copy(s,1,imin-1) ) - Hodnota( copy(s,imin+1, length(s)-imin ) ) else if s[imin]='*' then Hodnota := Hodnota( copy(s,1,imin-1) ) * Hodnota( copy(s,imin+1, length(s)-imin ) ) else if s[imin]='/' then Hodnota := Hodnota( copy(s,1,imin-1) ) div Hodnota( copy(s,imin+1, length(s)-imin ) ) end else if s[1]='(' then Hodnota := Hodnota( copy(s,2,length(s)-2 ) ) else begin x := 0; for i:=1 to length(s) do x := 10*x + ord( s[i] )-ord( '0' ); Hodnota := x end end; begin writeln( Hodnota('1') ); writeln( Hodnota('12') ); writeln( Hodnota('1+1') ); writeln( Hodnota('3*1+1') ); writeln( Hodnota('3*(1+1)') ); writeln( Hodnota('11*(2-36*4/18+37)-100*(4-2)') ); end.