Created
November 14, 2018 09:44
-
-
Save crazydiver/c67d421a4c0654789b99d150ebcd3fac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
pelment = ^telement; | |
telement = record | |
int:longint; | |
next:^telement; | |
end; | |
procedure push(var lr,rr:pelment; el:longint); | |
var | |
tmp:pelment; | |
begin | |
if lr = nil then | |
begin | |
new(tmp); | |
tmp^.int:=el; | |
tmp^.next:= rr; | |
rr:=tmp; | |
lr:=rr; | |
end | |
else | |
begin | |
new(lr^.next); | |
lr:=lr^.next; | |
lr^.next:=nil; | |
lr^.int:=el; | |
end; | |
end; | |
procedure pop(var lr,rr:pelment; var el:longint); | |
var | |
tmp:pelment; | |
begin | |
el:=lr^.int; | |
tmp:=lr; | |
lr:=lr^.next; | |
dispose(tmp); | |
if lr = nil then | |
rr:=nil; | |
end; | |
var | |
el,err:longint; | |
lr,rr:pelment; | |
com,fnc,num,check:string; | |
inp,outp:textfile; | |
begin | |
rr:=nil; | |
lr:=nil; | |
assign(inp,'input.txt'); | |
assign(outp,'output.txt'); | |
reset(inp); | |
rewrite(outp); | |
check:=''; | |
while not(eof(inp)) do | |
begin | |
readln(inp,com); | |
fnc:=copy(com,1,1); | |
if fnc = '+' then | |
begin | |
num:=copy(com,2,length(com)); | |
val(num,el,err); | |
if err=0 then | |
begin | |
val(num,el,err); | |
push(rr,lr,el); | |
end | |
else | |
check:='ERROR'; | |
end; | |
if fnc = '-' then | |
begin | |
if lr<>nil then | |
pop(lr,rr,el) | |
else | |
check:='ERROR'; | |
end; | |
end; | |
if (rr=nil)and(check<>'ERROR') then | |
write(outp,'EMPTY') | |
else | |
write(outp,check); | |
while (lr<>nil)and((check<>'ERROR')) do | |
begin | |
write(outp,lr^.int,' '); | |
lr:=lr^.next; | |
end; | |
close(inp); | |
close(outp); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment