Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Equilibrium-index/FreeBASIC/equilibrium-index.basic
Normal file
36
Task/Equilibrium-index/FreeBASIC/equilibrium-index.basic
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Sub equilibriumIndices (a() As Integer, b() As Integer)
|
||||
If UBound(a) = -1 Then Return '' empty array
|
||||
|
||||
Dim sum As Integer = 0
|
||||
Dim count As Integer = 0
|
||||
For i As Integer = LBound(a) To UBound(a) : sum += a(i) : Next
|
||||
Dim sumLeft As Integer = 0, sumRight As Integer = 0
|
||||
|
||||
For i As Integer = LBound(a) To UBound(a)
|
||||
sumRight = sum - sumLeft - a(i)
|
||||
If sumLeft = sumRight Then
|
||||
Redim Preserve b(0 To Count)
|
||||
b(count) = i
|
||||
count += 1
|
||||
End If
|
||||
sumLeft += a(i)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Dim a(0 To 6) As Integer = { -7, 1, 5, 2, -4, 3, 0 }
|
||||
Dim b() As Integer
|
||||
equilibriumIndices a(), b()
|
||||
If UBound(b) = -1 Then
|
||||
Print "There are no equilibrium indices"
|
||||
ElseIf UBound(b) = LBound(b) Then
|
||||
Print "The only equilibrium index is : "; b(LBound(b))
|
||||
Else
|
||||
Print "The equilibrium indices are : "
|
||||
For i As Integer = LBound(b) To UBound(b) : Print b(i); " "; : Next
|
||||
End If
|
||||
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue