REM*****************************************
REM***** Written by Kevin Rothenberger *****
REM******* Conrad Weiser High School *******
REM********** ACSL Problem #4 INT **********
REM********* Written in True BASIC *********
REM*****************************************
DIM input$(1)
DIM list$(20)
FOR loop=1 to 5
LET
list$(1)="A"
LET
list$(2)="B"
LET
list$(3)="C"
LET
list$(4)="D"
LET
list$(5)="E"
FOR i=6 to 20
LET
list$(i)=""
NEXT i
LET
out$=""
INPUT x$
LET counter=0
LET counter2=5
LET cnt=0
FOR i=1 to
len(x$)
IF
x$[i:i]=" " then
LET
counter=counter+1
MAT redim
input$(counter)
LET
input$(counter)=x$[1:i-1]
LET
x$[1:i]=""
LET i=1
ELSE IF
i=len(x$) then
LET
counter=counter+1
MAT redim
input$(counter)
LET
input$(counter)=x$[1:i]
END IF
NEXT i
FOR i=2 to
counter
IF input$(1)="S"
then
IF
input$(i)[1:3]="POP" then
FOR x=1
to val(input$(i)[4:4])
IF
counter2<>0 then
LET list$(counter2)=""
LET counter2=counter2-1
END
IF
NEXT x
ELSE IF
input$(i)[1:3]="PSH" then
LET
list$(counter2+1)=input$(i)[4:4]
LET
counter2=counter2+1
ELSE IF
input$(i)[1:3]="DUP" then
FOR j=1
to val(input$(i)[4:4])
LET
counter2=counter2+1
LET
list$(counter2)=list$(j)
NEXT j
ELSE IF
input$(i)[1:3]="SWP" then
LET
cnt=counter2
FOR
j=val(input$(i)[4:4]) to 1 step -1
LET
temp$=list$(cnt)
LET
list$(cnt)=list$(j)
LET
list$(j)=temp$
LET
cnt=cnt-1
NEXT j
ELSE IF
input$(i)[1:3]="SWH" then
LET
input$(1)="Q"
ELSE IF input$(i)[1:3]="CRC" then
FOR j=1
to val(input$(i)[4:4])
LET
temp$=list$(counter2)
FOR
x=counter2-1 to 1 step -1
LET list$(x+1)=list$(x)
NEXT x
LET list$(1)=temp$
NEXT j
ELSE IF
input$(i)[1:3]="PIN" then
FOR
x=counter2 to 1 step -1
LET
list$(x+1)=list$(x)
NEXT x
LET
list$(1)=input$(i)[4:4]
LET
counter2=counter2+1
ELSE IF
input$(i)[1:3]="PRT" then
IF
counter2=0 then
LET
out$="NIL"
ELSE
LET
cnt=counter2
FOR
j=1 to val(input$(i)[4:4])
LET out$=list$(cnt) & " " & out$
LET cnt=cnt-1
NEXT
j
END IF
PRINT
str$(loop) & ". " & out$
END IF
ELSE IF
input$(1)="Q" then
IF
input$(i)[1:3]="POP" then
FOR x=1
to val(input$(i)[4:4])
IF
counter2<>0 then
LET list$(1)=""
FOR j=1 to counter2
LET list$(j)=list$(j+1)
NEXT j
LET list$(counter2)=""
LET counter2=counter2-1
END
IF
NEXT x
ELSE IF
input$(i)[1:3]="PSH" then
LET
list$(counter2+1)=input$(i)[4:4]
LET
counter2=counter2+1
ELSE IF input$(i)[1:3]="DUP"
then
FOR j=1
to val(input$(i)[4:4])
LET
counter2=counter2+1
LET
list$(counter2)=list$(j)
NEXT j
ELSE IF
input$(i)[1:3]="SWP" then
LET
cnt=counter2
FOR
j=val(input$(i)[4:4]) to 1 step -1
LET
temp$=list$(cnt)
LET
list$(cnt)=list$(j)
LET
list$(j)=temp$
LET
cnt=cnt-1
NEXT j
ELSE IF
input$(i)[1:3]="SWH" then
LET
input$(1)="S"
ELSE IF
input$(i)[1:3]="CRC" then
FOR x=1
to val(input$(i)[4:4])
LET
temp$=list$(1)
FOR
j=1 to counter2
LET list$(j)=list$(j+1)
NEXT j
LET
list$(counter2)=temp$
NEXT x
ELSE IF
input$(i)[1:3]="PIN" then
FOR
x=counter2 to 1 step -1
LET
list$(x+1)=list$(x)
NEXT x
LET
list$(1)=input$(i)[4:4]
LET
counter2=counter2+1
ELSE IF
input$(i)[1:3]="PRT" then
IF
counter2=0 then
LET
out$="NIL"
ELSE
FOR
j=1 to val(input$(i)[4:4])
LET out$=out$ & list$(j) & " "
NEXT
j
END IF
PRINT
str$(loop) & ". " & out$
END IF
END IF
NEXT i
NEXT loop
END