Pagini recente » Cod sursa (job #2979877) | Cod sursa (job #1745644) | Cod sursa (job #2969037) | Cod sursa (job #2752) | Cod sursa (job #165982)
Cod sursa(job #165982)
program evaluare;
const
fin='evaluare.in';
fout='evaluare.out';
nmax=100000;
var
c:char;
function termen():longint;forward;
function factor():longint;forward;
function eval():longint;
var
rez:longint;
begin
rez:=termen();
while (c='+') or (c='-') do
if c='+' then
begin
read(c);
inc(rez,termen());
end
else
begin
read(c);
dec(rez,termen());
end;
eval:=rez;
end;
function termen():longint;
var
rez:longint;
begin
rez:=factor();
while (c='*')or(c='/') do
if c='*' then
begin
read(c);
rez:=rez*factor();
end
else
begin
read(c);
rez:=rez div factor();
end;
termen:=rez;
end;
function factor():longint;
var
rez:longint;
begin
if c='(' then
begin
read(c);
rez:=eval();
read(c);
end
else if (c<='9') and (c>='0') then
begin
rez:=ord(c)-48;
read(c);
while (c<='9') and (c>='0') do
begin
rez:=rez*10+ord(c)-48;
read(c);
end;
end;
factor:=rez;
end;
begin
assign(input,fin);
assign(output,fout);
rewrite(output);
reset(input);
read(c);
writeln(eval());
close(output);
close(input);
end.