Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim Array() As Byte = {102, 103, 105, 105, 104, 108, 101, 109, 111, 113} GnomeSort(Array, True) End Sub
' // Алгоритм гномьей сортировки Sub GnomeSort(ByRef Array() As Byte, ByVal ToUpper As Boolean) Dim tui As Integer, index As Integer, last As Integer If (ToUpper = True) Then tui = 1 Else tui = -1 index = 1 last = 2 Do If ((Array(index) * tui) < (Array(index - 1) * tui)) Then SWAP(Array(index), Array(index - 1)) index -= 1 If (index = 0) Then index = last last += 1 End If Else index = last last += 1 End If Loop While (index < (UBound(Array) + 1)) ' // c2fbefeeebede8eb3a20caf3eff0e8ffedeee220c42ec52e2028632920442d6d6f6e3535 End Sub
' // Функция обмена двух переменных Private Function SWAP(ByRef ic_a As Integer, ByRef ic_b As Integer) As Boolean Dim Dump As Integer = ic_a ic_a = ic_b ic_b = Dump Return True End Function
Type index='0'..'z'; var Ch:array[0..255] of integer; s:string; i,max,imax:integer; begin { очищаем массив счетчиков } for i:=0 to 255 do Ch[i]:=0; Writeln('Введите текст'); Readln(s); for i:=1 to Length(s) do Inc(Ch[Ord(s[i])]); max:=Ch[0]; imax:=0; for i:=33 to 255 do { не рассматриваем непечатаемые символы и пробел} if max<Ch[i]then begin max:=Ch[i]; imax:=i end; Writeln('Символ "',Chr(imax),'" встретился ',max,' раз(а)') end.
Тестовое решение: Введите текст "Что значит имя? Роза пахнет розой, хоть розой назови её, хоть нет." (В.Шекспир) Символ "о" встретился 9 раз(а)
Var i,n,k:integer; begin Writeln('15 чисел, кратных 19:'); i:=100; while i mod 19<>0 do Inc(i); { первое, кратное 19 } Write(i,' '); k:=1; while k<15 do begin i:=i+19; Write(i,' '); Inc(k) end; Writeln end.
Задача 2. var m,V,rho,rmax:real; i:integer; begin Writeln('Максимальная плотность материала для 30 тел.'); Writeln('Вводите через пробел массу тела (кг) и объем (куб.см)'); rmax:=0; for i:=1 to 3 do begin Write(i:2,': '); Read(m,V); rho:=m/V; if rmax<rho then rmax:=rho end; Writeln('Максимальная плотность равна ',rmax:0:3) end.
Dim Array() As Byte = {102, 103, 105, 105, 104, 108, 101, 109, 111, 113}
GnomeSort(Array, True)
End Sub
' // Алгоритм гномьей сортировки
Sub GnomeSort(ByRef Array() As Byte, ByVal ToUpper As Boolean)
Dim tui As Integer, index As Integer, last As Integer
If (ToUpper = True) Then tui = 1 Else tui = -1
index = 1
last = 2
Do
If ((Array(index) * tui) < (Array(index - 1) * tui)) Then
SWAP(Array(index), Array(index - 1))
index -= 1
If (index = 0) Then
index = last
last += 1
End If
Else
index = last
last += 1
End If
Loop While (index < (UBound(Array) + 1))
' // c2fbefeeebede8eb3a20caf3eff0e8ffedeee220c42ec52e2028632920442d6d6f6e3535
End Sub
' // Функция обмена двух переменных
Private Function SWAP(ByRef ic_a As Integer, ByRef ic_b As Integer) As Boolean
Dim Dump As Integer = ic_a
ic_a = ic_b
ic_b = Dump
Return True
End Function