REM*************Ben
Harakel**************
REM****ACSL
Senior Division Contest 2****
REM***************CELLS******************
DO
LET count=count+1
REM**********INITIALIZING
VARIABLES*****************
DIM f(8),h$(5),oh$(4)
LET input$=""
LET length=0
LET operator$=""
LET counter=0
LET first$=""
LET second$=""
FOR i = 1 to 4
LET h$(i)=""
LET oh$(i)=""
NEXT i
LET sorted$=""
LET sorted2$=""
LET new$=""
LET new2$=""
REM*************INPUT******************
PRINT
PRINT "Input "&str$(count)
PRINT
LINE INPUT input$
PRINT
PRINT "Output "&str$(count)
PRINT
LET length=len(input$)
FOR i= 1 to length
IF input$[i:i]<>"," then
LET operator$=operator$&input$[i:i]
LET counter=i
ELSE IF input$[i:i]="," then
LET counter=i
EXIT FOR
END IF
NEXT i
FOR i= (counter+1) to length
IF input$[i:i]<>"," then
LET first$=first$&input$[i:i]
LET counter=i
ELSE IF input$[i:i]="," then
LET counter=i
EXIT FOR
END IF
NEXT i
IF counter<length then
FOR i = (counter+1) to length
IF input$[i:i]<>","
then
LET second$=second$&input$[i:i]
LET counter=i
ELSE IF input$[i:i]=","
then
LET counter=i
EXIT FOR
END IF
NEXT i
END IF
REM************************DIVIDE***************************
IF operator$[1:6]="DIVIDE" then
FOR i = 1 to 4
LET h$(i)=first$[i:i]
NEXT i
FOR i= 5 to 8
LET oh$(i-4)=first$[i:i]
NEXT i
!
DO
LET flag=0
FOR i= 1 to 3
IF h$(i)>h$(i+1) then
LET temp$=h$(i)
LET h$(i)=h$(i+1)
LET h$(i+1)=temp$
LET flag=1
END IF
IF flag=1 then EXIT FOR
NEXT i
LOOP UNTIL flag=0
FOR i = 1 to 4
LET sorted$=sorted$&h$(i)
NEXT i
LET new1$=sorted$[1:4]&sorted$[1:4]
DO
LET flag=0
FOR i= 1 to 3
IF oh$(i)>oh$(i+1) then
LET temp$=oh$(i)
LET oh$(i)=oh$(i+1)
LET oh$(i+1)=temp$
LET flag=1
END IF
IF flag=1 then EXIT FOR
NEXT i
LOOP UNTIL flag=0
FOR i = 1 to 4
LET sorted2$=sorted2$&oh$(i)
NEXT i
LET new2$=sorted2$[1:4]&sorted2$[1:4]
PRINT new1$
PRINT new2$
REM*************************ADD*********************************
ELSE IF operator$[1:3]="ADD" then
LET place=val(operator$[4:4])
FOR i = 1 to place+1
LET h$(i)=first$[i:i]
NEXT i
DO
LET flag=0
FOR i= 1 to place-1
IF h$(i)>h$(i+1) then
LET temp$=h$(i)
LET h$(i)=h$(i+1)
LET h$(i+1)=temp$
LET flag=1
END IF
IF flag=1 then EXIT FOR
NEXT i
LOOP UNTIL flag=0
FOR i = 1 to place+1
LET sorted$=sorted$&h$(i)
NEXT i
LET new$=first$[1:place]&sorted$[1:place]&first$[place+1:(8-place)]
PRINT new$
REM***************************SUBTRACT=***************************
ELSE IF operator$[1:8]="SUBTRACT"
then
LET place=val(operator$[9:9])
FOR i = 1 to place
LET h$(i)=first$[8-place+i:8-place+i]
NEXT i
DO
LET flag=0
FOR i= 1 to place-1
IF h$(i)>h$(i+1) then
LET temp$=h$(i)
LET h$(i)=h$(i+1)
LET h$(i+1)=temp$
LET flag=1
END IF
IF flag=1 then EXIT FOR
NEXT i
LOOP UNTIL flag=0
FOR i= 1 to place+1
LET sorted$=sorted$&h$(i)
NEXT i
LET new$=first$[(place+1):(8-place)]&first$[(8-(place-1)):8]&sorted$[1:place]
PRINT new$
REM****************************UNION**********************************
ELSE IF operator$[1:5]="UNION"
then
FOR i= 1 to 4
LET h$(i)=first$[i+4:i+4]
NEXT i
DO
LET flag=0
FOR i= 1 to 3
IF h$(i)>h$(i+1) then
LET temp$=h$(i)
LET h$(i)=h$(i+1)
LET h$(i+1)=temp$
LET flag=1
END IF
IF flag=1 then EXIT FOR
NEXT i
LOOP UNTIL flag=0
FOR i = 1 to 4
LET sorted$=sorted$&h$(i)
NEXT i
FOR i = 1 to 4
LET oh$(i)=second$[i:i]
NEXT i
DO
LET flag=0
FOR i= 1 to 3
IF oh$(i)>oh$(i+1) then
LET temp$=oh$(i)
LET oh$(i)=oh$(i+1)
LET oh$(i+1)=temp$
LET flag=1
END IF
IF flag=1 then EXIT FOR
NEXT i
LOOP UNTIL flag=0
FOR i = 1 to 4
LET sorted2$=sorted2$&oh$(i)
NEXT i
LET new$=sorted$[1:4]&sorted2$[1:4]
PRINT new$
REM*****************************INTERSECT*********************************
ELSE IF operator$[1:9]="INTERSECT"
then
FOR i= 1 to 2
LET h$(i)=first$[i:i]
NEXT i
FOR i = 3 to 4
LET h$(i)=first$[i+4:i+4]
NEXT i
FOR i= 1 to 2
LET oh$(i)=second$[i:i]
NEXT i
FOR i = 3 to 4
LET oh$(i)=second$[i+4:i+4]
NEXT i
DO
LET flag=0
FOR i= 1 to 3
IF h$(i)>h$(i+1) then
LET temp$=h$(i)
LET h$(i)=h$(i+1)
LET h$(i+1)=temp$
LET flag=1
END IF
IF flag=1 then EXIT FOR
NEXT i
LOOP UNTIL flag=0
FOR i = 1 to 4
LET sorted$=sorted$&h$(i)
NEXT i
DO
LET flag=0
FOR i= 1 to 3
IF oh$(i)>oh$(i+1) then
LET temp$=oh$(i)
LET oh$(i)=oh$(i+1)
LET oh$(i+1)=temp$
LET flag=1
END IF
IF flag=1 then EXIT FOR
NEXT i
LOOP UNTIL flag=0
FOR i = 1 to 4
LET sorted2$=sorted2$&oh$(i)
NEXT i
LET new$=sorted$[1:4]&sorted2$[1:4]
PRINT new$
REM**************************************************************
ELSE
END IF
LOOP UNTIL
count=5
END