const deyst: set of char = ['+','-','*','/','(',')','^']; var i1,i2,i3,i4 : byte; a : string; ret : longint; function calc(var sum : longint; num:longint;dey:char) : boolean; var i : byte; res : longint; begin case dey of '^': begin if num = 0 then sum:=1; res:=sum; for i := 2 to num do sum:=res*sum; end; '+': sum := sum + num; '-': sum := sum - num; '*': sum := sum * num; '/': if num <> 0 then sum := sum div num else Begin calc := false; exit; End; end; calc := true; end; function Findnum(a:string;pos,dir:byte):longint; var ret :longint; st :string; code :integer; begin st:=''; if dir = 1 then inc(pos) else dec(pos); if dir = 1 then while (not (a[pos] in deyst))and(pos<>length(a)+1) do begin st := st + a[pos]; inc(pos); end else while (not (a[pos] in deyst)) and (pos<>0) do begin insert(a[pos],st,1); dec(pos); end; if (pos=1)and(a[pos]='-') then insert(a[pos],st,1); if st[1] = '.' then st[1] :='-'; Val(st,ret,code); FindNum:=ret; end;{FindNum} Procedure Ends(st:string); begin Writeln(st); Halt(3); end; Function Calculate(a:string):string; var res : longint; j,i : byte; code : integer; ch : byte; num1,num2 : longint; tmp1,tmp2 : string; min : boolean; begin if a[1] = '-' then a[1] := '.'; while pos(' ',a) <> 0 do delete(a,pos(' ',a),1); if (pos('(',a)<>0) or (pos(')',a)<>0) then begin j:=pos('(',a); if j = 0 then Ends('Ошибка в скобках'); i := 1; ch := j+1; while i <> 0 do begin if a[ch] = '(' then inc(i); if a[ch] = ')' then dec(i); inc(ch); end; tmp1:=copy(a,j+1,ch-j-2); tmp1:=calculate(tmp1); delete(a,j,ch-j); insert(tmp1,a,j); end; while (pos('^',a)<>0) do begin i := pos('^',a); num1 := findnum(a,i,0); str(num1,tmp1); num2 := findnum(a,i,1); str(num2,tmp2); calc(num1,num2,a[i]); delete(a,i-length(tmp1),length(tmp1)+1+length(tmp2)); str(num1,tmp2); insert(tmp2,a,i-length(tmp1)) end; while (pos('*',a)<>0)or(pos('/',a)<>0) do begin i := pos('*',a); j := pos('/',a); if ((i0) then begin num1 := findnum(a,i,0); str(num1,tmp1); num2 := findnum(a,i,1); str(num2,tmp2); calc(num1,num2,a[i]); delete(a,i-length(tmp1),length(tmp1)+1+length(tmp2)); str(num1,tmp2); if tmp2[1] = '-' then tmp2[1]:='.'; insert(tmp2,a,i-length(tmp1)) end else begin num1 := findnum(a,j,0); str(num1,tmp1); num2 := findnum(a,j,1); str(num2,tmp2); calc(num1,num2,a[j]); delete(a,j-length(tmp1),length(tmp1)+1+length(tmp2)); str(num1,tmp2); if tmp2[1] = '-' then tmp2[1]:='.'; insert(tmp2,a,j-length(tmp1)) end; end; min:=true; while ((pos('+',a)<>0)or(pos('-',a)<>0)) and min do begin i := pos('+',a); j := pos('-',a); if ((i0) then begin num1 := findnum(a,i,0); str(num1,tmp1); num2 := findnum(a,i,1); str(num2,tmp2); calc(num1,num2,a[i]); delete(a,i-length(tmp1),length(tmp1)+1+length(tmp2)); str(num1,tmp2); if tmp2[1] = '-' then tmp2[1]:='.'; insert(tmp2,a,i-length(tmp1)) end else begin num1 := findnum(a,j,0); str(num1,tmp1); num2 := findnum(a,j,1); str(num2,tmp2); calc(num1,num2,a[j]); delete(a,j-length(tmp1),length(tmp1)+1+length(tmp2)); str(num1,tmp2); if tmp2[1] = '-' then tmp2[1]:='.'; insert(tmp2,a,j-length(tmp1)) end; end; calculate:=a; end; Function Simply(a:string):longint; var res:longint; code:integer; begin a:=Calculate(a); if a[1] = '.' then a[1] :='-'; val(a,res,code); Simply:=res; end; begin WriteLN('Введите пример: '); ReadLn(a); WriteLn(Simply(a)); readln end.