Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
56
Task/Set-consolidation/FreeBASIC/set-consolidation.basic
Normal file
56
Task/Set-consolidation/FreeBASIC/set-consolidation.basic
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
Function Consolidate(s As String) As String
|
||||
Dim As Integer i, j, k, p, n, pio, fin
|
||||
Dim As String ts, sets(0 To 100), temp
|
||||
|
||||
' 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
|
||||
n += 1
|
||||
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 += Mid(sets(p), k, 1)
|
||||
End If
|
||||
Next k
|
||||
If Len(ts) < Len(sets(p)) Then
|
||||
If j > 0 Then
|
||||
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
|
||||
|
||||
Dim As String test(3) = {"AB", "AB,CD", "AB,CD,DB", "HIK,AB,CD,DB,FGH"}
|
||||
For t As Integer = Lbound(test) To Ubound(test)
|
||||
Print Consolidate(test(t))
|
||||
Next t
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue