Cod sursa(job #640239)
Program expresie;
var a:array [1..100001] of char;
i:longint;
fi,fo:text;
function rez():longint;forward;
function factor():longint;
var x:longint;
begin
x:=0;
if a[i]='(' then begin inc(i); x:=rez(); inc(i); end
else while (a[i]>='0') and (a[i]<='9') do begin
x:=x*10+ord(a[i])-48;
inc(i);
end;
factor:=x;
end;
function termen():longint;
var y:longint;
begin
y:=factor;
while (a[i]='*') or (a[i]='/') do
if a[i]='*' then begin inc(i); y:=y*factor(); end
else begin inc(i); y:=y div factor(); end;
termen:=y;
end;
function rez():longint;
var v:longint;
begin
v:=termen();
while (a[i]='+') or (a[i]='-') do
if a[i]='+' then begin
inc(i);
v:=v+termen();
end
else begin inc(i); v:=v-termen(); end;
rez:=v;
end;
begin
assign(fi,'evaluare.in');
assign(fo,'evaluare.out');
reset(fi); rewrite(fo);
i:=1;
while not seekeoln(fi) do begin read(fi,a[i]); inc(i); end;
i:=1;
write(fo,rez);
close(fo);
end.