Pagini recente » Cod sursa (job #2397300) | Cod sursa (job #3146545) | Cod sursa (job #611626) | Cod sursa (job #960507) | Cod sursa (job #1549837)
var s:string;
n:longint;
function termen:real; forward;
function factor:real; forward;
function eval:real;
var r:real;
begin
r:=termen;
while (n<=length(s)) and ((s[n]='+') or (s[n]='-')) do begin
inc(n);
if s[n-1]='+' then r:=r+termen
else r:=r-termen
end;
eval:=r;
end;
function termen:real;
var r:real;
begin
r:=factor;
while (n<=length(s)) and ((s[n]='*') or (s[n]='/')) do begin
inc(n);
if s[n-1]='*' then r:=r*factor
else r:=r div factor;
end;
termen:=r;
end;
function factor:real;
var r:real;
begin
r:=0;
if s[n]='(' then begin
inc(n);
r:=eval;
inc(n);
end else begin
while (n<=length(s)) and ((s[n]>='0') and (s[n]<='9')) do begin
r:=r*10+ord(s[n])-ord('0');
inc(n);
end;
end;
factor:=r;
end;
begin
assign(input,'evaluare.in');
assign(output,'evaluare.out');
reset(input);
rewrite(output);
read(s);
n:=1;
write(eval);
end.