Pagini recente » Cod sursa (job #947948) | Cod sursa (job #1419128) | Cod sursa (job #1633539) | Cod sursa (job #2442860) | Cod sursa (job #1213150)
program evaluareexpresie;
var bufin:array[1..100000]of longint;
s:ansistring;
i,n:longint;
function expresie:longint; forward;
function factor:longint;
var x:longint;
begin
if s[i]='(' then
begin
inc(i);
factor:=expresie;
inc(i);
end else
begin
x:=0;
while (i<=n)and(s[i] in ['0'..'9']) do
begin
x:=x*10+ord(s[i])-ord('0');
inc(i);
end;
factor:=x;
end;
end;
function termen:longint;
var x:longint;
begin
x:=factor;
while (i<=n)and(s[i] in ['*','/']) do
if s[i]='*' then
begin
inc(i);
x:=x*factor;
end else
if s[i]='/' then
begin
inc(i);
x:=x div factor;
end;
termen:=x;
end;
function expresie:longint;
var x:longint;
begin
x:=termen;
while (i<=n)and(s[i] in ['+','-']) do
begin
if s[i]='+' then
begin
inc(i);
x:=x+termen;
end else
begin
inc(i);
x:=x-termen;
end;
end;
expresie:=x;
end;
begin
assign(input,'evaluare.in');
reset(input);
settextbuf(input,bufin);
assign(output,'evaluare.out');
rewrite(output);
readln(s);inc(i);
n:=length(s);
writeln(expresie);
close(output);
end.