Pagini recente » Cod sursa (job #2456444) | Istoria paginii runda/cerculdeinfo-lectia7-grafuri | Cod sursa (job #482372) | Cod sursa (job #2407089) | Cod sursa (job #831853)
Cod sursa(job #831853)
var s:array[1..1000000] of char;
i:longint;
f,g:text;
function expresie:longint;
forward;
function factor:longint;
var x:longint;
begin
x:=0;
if s[i]='(' then
begin
i:=i+1;
x:=expresie;
i:=i+1;
end
else
while (s[i]<='9') and (s[i]>='0') do
begin
x:=x*10+ord(s[i])-48;
i:=i+1;
end;
factor:=x;
end;
function termen:longint;
var y:longint;
begin
y:=factor;
while (s[i]='*') or (s[i]='/') do
if s[i]='*' then
begin
i:=i+1;
y:=y*factor;
end
else
begin
i:=i+1;
y:=y div factor;
end;
termen:=y;
end;
function expresie:longint;
var z:longint;
begin
z:=termen;
while (s[i]='+') or (s[i]='-') do
if s[i]='+' then
begin
i:=i+1;
z:=z+termen;
end
else
begin
i:=i+1;
z:=z-termen;
end;
expresie:=z;
end;
begin
assign(f,'evaluare.in');
reset(f);
read(f,s);
assign(g,'evaluare.out');
rewrite(g);
i:=1;
write(g,expresie);
close(f);
close(g);
end.