Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
68
Task/Set-consolidation/XBasic/set-consolidation.basic
Normal file
68
Task/Set-consolidation/XBasic/set-consolidation.basic
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
PROGRAM "Set consolidation"
|
||||
VERSION "0.0001"
|
||||
|
||||
DECLARE FUNCTION Entry ()
|
||||
DECLARE FUNCTION Consolidate$ (s$)
|
||||
|
||||
FUNCTION Entry ()
|
||||
DIM test$[4]
|
||||
test$[0] = "AB"
|
||||
test$[1] = "AB,CD"
|
||||
test$[2] = "AB,CD,DB"
|
||||
test$[3] = "HIK,AB,CD,DB,FGH"
|
||||
FOR t = 0 TO 3
|
||||
PRINT Consolidate$(test$[t])
|
||||
NEXT t
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION Consolidate$ (s$)
|
||||
DIM sets$[100]
|
||||
|
||||
' Split the STRING into substrings
|
||||
pio = 1
|
||||
n = 0
|
||||
FOR i = 1 TO LEN(s$)
|
||||
IF MID$(s$, i, 1) = "," THEN
|
||||
fin = i - 1
|
||||
sets$[n] = MID$(s$, pio, fin - pio + 1)
|
||||
pio = i + 1
|
||||
INC n
|
||||
END IF
|
||||
NEXT i
|
||||
sets$[n] = MID$(s$, pio, LEN(s$) - pio + 1)
|
||||
|
||||
' Main logic
|
||||
FOR i = 0 TO n
|
||||
p = i
|
||||
ts$ = ""
|
||||
FOR j = i TO 0 STEP -1
|
||||
IF ts$ = "" THEN p = j
|
||||
ts$ = ""
|
||||
FOR k = 1 TO LEN(sets$[p])
|
||||
IF j > 0 THEN
|
||||
IF INSTR(sets$[j-1], MID$(sets$[p], k, 1)) = 0 THEN
|
||||
ts$ = ts$ + MID$(sets$[p], k, 1)
|
||||
END IF
|
||||
END IF
|
||||
NEXT k
|
||||
IF LEN(ts$) < LEN(sets$[p]) THEN
|
||||
IF j > 0 THEN
|
||||
sets$[j-1] = sets$[j-1] + ts$
|
||||
sets$[p] = "-"
|
||||
ts$ = ""
|
||||
END IF
|
||||
ELSE
|
||||
p = i
|
||||
END IF
|
||||
NEXT j
|
||||
NEXT i
|
||||
|
||||
' Join the substrings into a STRING
|
||||
temp$ = sets$[0]
|
||||
FOR i = 1 TO n
|
||||
temp$ = temp$ + "," + sets$[i]
|
||||
NEXT i
|
||||
|
||||
RETURN s$ + " = " + temp$
|
||||
END FUNCTION
|
||||
END PROGRAM
|
||||
Loading…
Add table
Add a link
Reference in a new issue