Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
60
Task/Set-consolidation/BASIC256/set-consolidation.basic
Normal file
60
Task/Set-consolidation/BASIC256/set-consolidation.basic
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
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 #test$[?]
|
||||
print Consolidate(test$[t])
|
||||
next t
|
||||
end
|
||||
|
||||
function Consolidate(s$)
|
||||
dim sets$(100)
|
||||
|
||||
# Split the string into substrings
|
||||
pio = 1
|
||||
n = 0
|
||||
for i = 1 to length(s$)
|
||||
if mid(s$, i, 1) = "," then
|
||||
fin = i - 1
|
||||
sets$[n] = mid(s$, pio, fin - pio + 1)
|
||||
pio = i + 1
|
||||
n += 1
|
||||
end if
|
||||
next i
|
||||
sets$[n] = mid(s$, pio, length(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 length(sets$[p])
|
||||
if j > 0 then
|
||||
if instr(sets$[j-1], mid(sets$[p], k, 1)) = 0 then
|
||||
ts$ += mid(sets$[p], k, 1)
|
||||
end if
|
||||
end if
|
||||
next k
|
||||
if length(ts$) < length(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$ += "," + sets$[i]
|
||||
next i
|
||||
|
||||
return s$ + " = " + temp$
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue