! ***** ACSL 2013
Contest #2 Intermediate *****
! ***** Mason Albright *****
! * Variables:
operation$ = the operation of the input
! * cell$ = the primary cell
! * cell2$ = the secondary cell, used in
! * divide, union, and
intersect
! * n = the non-cell operand
! * Note:
pos(input$,",",pos(input$,",",0)+1)
! * = position of the second comma
DO
! *** Gathering Input ***
PRINT
LINE INPUT prompt "Input: ":input$
LET operation$ =
ucase$(input$[0:pos(input$,",",0)-1])
IF
pos(input$,",",pos(input$,",",0)+1) >
pos(input$,",",0) then
LET cell$ =
trim$(ucase$(input$[pos(input$,",",0)+1:pos(input$,",",pos(input$,",",0)+1)-1]))
LET cell2$ =
trim$(ucase$(input$[pos(input$,",",pos(input$,",",0)+1)+1:len(input$)]))
ELSE
LET cell$ =
trim$(ucase$(input$[pos(input$,",",0)+1:len(input$)]))
END IF
IF operation$ <> "DIVIDE"
and operation$ <> "UNION" and operation$ <>
"INTERSECT" then
LET n =
val(operation$[len(operation$):len(operation$)])
LET operation$ =
operation$[0:len(operation$)-1]
END IF
! ***
IF operation$ = "ADD" then
! *** Adding ***
LET
cell$ = (cell$[0:n])&(cell$[0:8-n])
ELSE IF operation$ = "SUBTRACT"
then
! *** Subtracting ***
LET cell$ =
(cell$[n+1:8])&(cell$[9-n:8])
ELSE IF operation$ = "DIVIDE" then
! *** Dividing ***
LET cell2$ =
(cell$[5:8])&(cell$[5:8])
LET cell$ = (cell$[0:4])&(cell$[0:4])
ELSE IF operation$ = "UNION" then
! *** Uniting ***
LET cell$ =
(cell$[5:8])&(cell2$[0:4])
ELSE IF operation$ = "INTERSECT"
then
! *** Intersecting ***
LET cell$ =
(cell$[0:2])&(cell$[7:8])&(cell2$[0:2])&(cell2$[7:8])
END IF
! *** Printing Output ***
IF operation$ <> "DIVIDE"
then
PRINT "Output: ";cell$
ELSE
PRINT "Output: ";cell$;"
and ";cell2$
END IF
PRINT
! ***
LOOP
END