Advertisement
mabu

Сортировка по квадратам соседних пар

Aug 27th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Module Main
  2.    
  3.     Public Function Main(ByVal Args() As String)As Integer
  4.         ' Индекс элемента
  5.         Dim i As Integer
  6.         ' Список
  7.         Dim q = Enumerable.Range(1, 17).ToArray
  8.         ' Квадраты 4 9 16 25
  9.         Dim f = Enumerable.Range(2, 4).Select(Function (x As Integer) x * x).ToArray
  10.         ' Количество ложных совпадений
  11.         Dim FalseCount As Integer
  12.         Do
  13.             If f.Contains(q(i) + q(i + 1)) Then
  14.                 i += 1
  15.                 FalseCount = 0
  16.             Else
  17.                 For t As Integer = i + 1 To q.Length - 2
  18.                     Dim d As Integer = q(t)
  19.                     q(t) = q(t + 1)
  20.                     q(t+ 1) = d
  21.                 Next
  22.                 FalseCount += 1
  23.                 If FalseCount > q.Length Then
  24.                     i = 0
  25.                     FalseCount = 0
  26.                     For t As Integer = 0 To q.Length - 2
  27.                         Dim d As Integer = q(t)
  28.                         q(t) = q(t + 1)
  29.                         q(t+ 1) = d
  30.                     Next
  31.                 End If
  32.             End If
  33.         Loop Until i >= q.Length - 2 ' Идти до тех пор, пока не превысим коллекцию -2 элемента
  34.        
  35.         For Each i In q
  36.             Console.Write(i & " ")
  37.         Next
  38.        
  39.         Return 0
  40.     End Function
  41. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement