var i1,i2,i3,i4 : byte; a : string; ret : longint; function calc(var sum : longint; num:longint;dey:char) : boolean; begin case dey of '+': 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 ['+','-','*','/','(',')']))and(pos<>length(a)+1) do begin st := st + a[pos]; inc(pos); end else while (not (a[pos] in ['+','-','*','/','(',')'])) 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} function Simply(a : string): longint; var res : longint; j,i : byte; code : integer; 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); 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(num2,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; if a[1] = '.' then a[1] :='-'; val(a,res,code); Simply:=res; end; begin WriteLN('Введите пример: '); ReadLn(a); WriteLn(Simply(a)); readln end.