Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
58
Task/Set-consolidation/Gambas/set-consolidation.gambas
Normal file
58
Task/Set-consolidation/Gambas/set-consolidation.gambas
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
Public test As String[] = ["AB", "AB,CD", "AB,CD,DB", "HIK,AB,CD,DB,FGH"]
|
||||
|
||||
Public Sub Main()
|
||||
|
||||
For t As Integer = 0 To test.Max
|
||||
Print Consolidate(test[t])
|
||||
Next
|
||||
|
||||
End
|
||||
|
||||
Public Function Consolidate(s As String) As String
|
||||
|
||||
Dim sets As New String[100]
|
||||
Dim n As Integer, i As Integer, j As Integer, k As Integer, p As Integer
|
||||
Dim ts As String, tmp As String
|
||||
|
||||
n = 0
|
||||
For i = 1 To Len(s)
|
||||
If Mid(s, i, 1) = "," Then
|
||||
n += 1
|
||||
Else
|
||||
sets[n] = sets[n] & Mid(s, i, 1)
|
||||
Endif
|
||||
Next
|
||||
|
||||
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)
|
||||
Endif
|
||||
Endif
|
||||
Next
|
||||
If Len(ts) < Len(sets[p]) Then
|
||||
If j > 0 Then
|
||||
sets[j - 1] &= ts
|
||||
sets[p] = "-"
|
||||
ts = ""
|
||||
Endif
|
||||
Else
|
||||
p = i
|
||||
Endif
|
||||
Next
|
||||
Next
|
||||
|
||||
tmp = sets[0]
|
||||
For i = 1 To n
|
||||
tmp &= "," & sets[i]
|
||||
Next
|
||||
|
||||
Return s & " = " & tmp
|
||||
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue