Pagini recente » Cod sursa (job #722894) | Cod sursa (job #992435) | Cod sursa (job #1144871) | Cod sursa (job #2204785) | Cod sursa (job #1549844)
var s:string;
n:longint;
function termen:longint; forward;
function factor:longint; forward;
function eval:longint;
var r:longint;
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:longint;
var r:longint;
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:longint;
var r:longint;
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.