Cod sursa(job #243362)
Utilizator | Data | 12 ianuarie 2009 19:54:32 | |
---|---|---|---|
Problema | Evaluarea unei expresii | Scor | 100 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 1.54 kb |
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.