Pagini recente » Cod sursa (job #2861154) | Cod sursa (job #2496294) | Cod sursa (job #1056353) | Cod sursa (job #2816669) | Cod sursa (job #243362)
Cod sursa(job #243362)
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);
writeln(eval);
close(input); close(output);
end.