Pagini recente » Cod sursa (job #1284603) | Cod sursa (job #2891890) | Cod sursa (job #2373754) | Cod sursa (job #1846988) | Cod sursa (job #168734)
Cod sursa(job #168734)
program eval2;
var c : char;
function termen:longint;forward;
function factor:longint;forward;
function eval:longint;
var r : longint;
begin
r := termen;
while (c='+') or (c='-') do
if c='+' then begin
read(c);
r := r+termen;
end
else begin
read(c);
r := r-termen;
end;
eval := r;
end;
function termen:longint;
var r : longint;
begin
r := factor;
while (c='*') or (c='/') do
if c='*' then begin
read(c);
r := r*factor;
end
else begin
read(c);
r := r div factor;
end;
termen := r;
end;
function factor:longint;
var r : longint;
begin
r := 0;
if c='(' then begin
read(c);
r := eval;
read(c);
end
else while (c>='0') and (c<='9') do begin
r := r*10+ord(c)-ord('0');
read(c);
end;
factor := r;
end;
begin
assign(input,'evaluare.in');
reset(input);
assign(output,'evaluare.out');
rewrite(output);
read(c);
write(eval);
close(input);
close(output);
end.