Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
46
Task/Range-extraction/FreeBASIC/range-extraction.basic
Normal file
46
Task/Range-extraction/FreeBASIC/range-extraction.basic
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Function formatRange (a() As Integer) As String
|
||||
Dim lb As Integer = LBound(a)
|
||||
Dim ub As Integer = UBound(a)
|
||||
If ub = - 1 Then Return ""
|
||||
If lb = ub Then Return Str(a(lb))
|
||||
Dim rangeCount As Integer = 1
|
||||
Dim range As String = Str(a(lb))
|
||||
For i As Integer = lb + 1 To ub
|
||||
If a(i) = a(i - 1) + 1 Then
|
||||
rangeCount += 1
|
||||
ElseIf rangeCount = 1 Then
|
||||
range += "," + Str(a(i))
|
||||
ElseIf rangeCount = 2 Then
|
||||
rangeCount = 1
|
||||
range += "," + Str(a(i-1)) + "," + Str(a(i))
|
||||
Else
|
||||
rangeCount = 1
|
||||
range += "-" + Str(a(i-1)) + "," + Str(a(i))
|
||||
End If
|
||||
Next
|
||||
If rangeCount = 2 Then
|
||||
range += "," + Str(a(ub))
|
||||
ElseIf rangeCount > 2 Then
|
||||
range += "-" + Str(a(ub))
|
||||
End If
|
||||
Return range
|
||||
End Function
|
||||
|
||||
Dim a(1 To 20) As Integer = {-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20}
|
||||
Print formatRange(a())
|
||||
Print
|
||||
|
||||
Dim b(1 To 33) As Integer => _
|
||||
{ _
|
||||
0, 1, 2, 4, 6, 7, 8, 11, 12, 14, _
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, _
|
||||
25, 27, 28, 29, 30, 31, 32, 33, 35, 36, _
|
||||
37, 38, 39 _
|
||||
}
|
||||
|
||||
Print formatRange(b())
|
||||
Print
|
||||
Print "Press any key to continue"
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue