Pagini recente » Monitorul de evaluare | Profil Andrei-27 | Clasament dupa rating | Monitorul de evaluare | Cod sursa (job #174016)
Cod sursa(job #174016)
const cifre=['0'..'9'];
var v:array[1..100000] of char;
l,i:longint;
s:string;
f,g:text;
function eval(var p:longint):longint;forward;
function fac(var p:longint):longint;
var r,nr:longint;
begin
if p>l then exit;
r:=0; nr:=0;
if v[p]='(' then
begin
inc(p);
r:=eval(p);
inc(p);
end;
if v[p]=')' then
begin
inc(p);
fac:=0;
exit;
end;
if v[p] in cifre then
repeat
nr:=nr*10+ord(v[p])-ord('0');
inc(p)
until not(v[p] in cifre);
fac:=r+nr;
end;
function ter(var p:longint):longint;
var r:LONGINT;
begin
r:=0;
if p>l then exit;
r:=fac(p);
while v[p] in ['*','/'] do
begin
if v[p]='*' then begin
inc(p);
r:=r*fac(p); break;
end;
if v[p]='/' then begin
inc(p);
r:=r div fac(p); break;
end;
end;
ter:=r;
end;
function eval(var p:longint):longint;
var r:longint;
begin
r:=0;
if p>l then exit;
r:=ter(p);
while v[p] in ['-','+'] do
begin
if v[p]='+' then
begin
inc(p);
r:=r+ter(p); break;
end;
if v[p]='-' then
begin
inc(p);
r:=r-ter(p); break;
end;
end;
eval:=r;
end;
procedure cit;
var x:char;
begin
assign(f,'evaluare.in'); reset(f);
assign(g,'evaluare.out'); rewrite(g);
while not eoln(f) do
begin
read(f,x);
inc(l); v[l]:=x;
end;
close(f); reset(f); readln(f,s);
end;
begin
cit; i:=1;
writeln(g,eval(i));
close(g);
end.