Pagini recente » Cod sursa (job #2880018) | Cod sursa (job #1864740) | Cod sursa (job #1029210) | Monitorul de evaluare | Cod sursa (job #349631)
Cod sursa(job #349631)
nod=^node;
node=record
x:longint;
next:nod;
var s,t:array[1..100000] of char;
output:array[1..100000] of longint;
st:nod;
f,g:text;
v:string[10];
procedure introdu_in_t;
begin
for qq:=1 to j do begin
tt:=tt+1; t[tt]:=v[qq]; end;
end;
procedure introdu_stiva;
begin
new(p);
p^.x:=s[i];
p^.next:=cap;
cap:=p;
end;
procedure scoate_stiva;
begin
okk:=true;
while okk and cap<>nil do
if cap^.x<>'(' then
begin
tt:=tt+1;
t[tt]:=cap^.x;
cap:=cap^.next;
end else begin okk:=false; cap:=cap^.next; end;
end;
begin
assign(f,'evaluare.in'); assign(g,'evaluare.out'); tt:=0;
reset(f); rewrite(g); n:=0; cap:=nil;
while not eof(f) do
begin
read(f,c);
n:=n+1;
s[n]:=c;
end;
i:=1;
while i<=n do
begin
if (s[i]>='0') and (s[i]<=9) then
begin
j:=1; v[1]:=s[i];
ok:=true;
while ok and i+1<=n do
begin
i:=i+1; j:=j+1; if (s[i]>='0') and (s[i]<='9') then
v[j]:=s[i] else ok:=false;
end;
introdu_in_t;
end;
if (s[i]='+') or (s[i]='-') then
begin
scoate_stiva;
introdu_stiva;
end;
if (s[i]='*') or (s[i]='/') then
begin
introdu_stiva;
end;
if (s[i]='(') or (s[i]=')') then paranteze;
end;