2008年12月31日 星期三

二元搜尋 -- 料一甲55王小明

Public Class Form1
    Dim i
    Dim str1 = "未找到"
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim s = Val(InputBox("請輸入要找的值?"))
        'Dim s = 22
        Dim a() = {2, 1, 5, 10, 22, 34, 17}
        Array.Sort(a)
        Dim low = 0
        Dim high = UBound(a)
        Dim m = 99999
        While low <= high And s <> m
            m = Int((low + high) / 2)
            If a(m) = s Then
                str1 = "找到了在排序後的註標" & m & "處"
                Exit While
            Else
                If a(m) < s Then
                    low = m + 1
                Else
                    high = m - 1
                End If
            End If
        End While
        MsgBox(str1)
    End Sub
End Class

循序搜尋 -- 精簡版

Public Class Form1
    Dim i
    Dim str1 = "未找到"
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim s = Val(InputBox("請輸入要找的值?"))
        Dim a() = {2, 1, 5, 10, 22, 34, 17}
        For i = 0 To 6
            If a(i) = s Then
                str1 = "找到了在註標" & i & "處"
            End If
        Next
        MsgBox(str1)
    End Sub
End Class

除錯練習 -- 二元搜尋

'請找出為何以下搜尋程式,輸入1及34找不到,而其他值都沒有問題

Public Class Form1
    Dim i
    Dim isFound = False
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim s = Val(InputBox("請輸入要找的值?"))
        'Dim s = 22
        Dim sN
        Dim a() = {2, 1, 5, 10, 22, 34, 17}
        Array.Sort(a)
        Dim low = 0
        Dim high = UBound(a)
        Dim m
        While low < high And Not isFound
            m = Int((low + high) / 2)
            If a(m) = s Then
                isFound = True
                sN = m
                Exit While
            Else
                If a(m) < s Then
                    low = m + 1
                Else
                    high = m - 1
                End If
            End If
        End While
        If isFound = True Then
            MsgBox("找到了在排序後的註標" & sN & "處")
            MsgBox("也就是在排序後一般習慣稱的第" & sN + 1 & "個")
        Else
            MsgBox("未找到")
        End If
    End Sub
End Class

循序搜尋例

 

image

image

image

 

Public Class Form1
    Dim i
    Dim isFound = False
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim s = Val(InputBox("請輸入要找的值?"))
        Dim sN
        Dim a() = {2, 1, 5, 10, 22, 34, 17}
        For i = 0 To 6
            If a(i) = s Then
                isFound = True
                sN = i
            End If
        Next
        If isFound = True Then
            MsgBox("找到了在註標" & sN & "處")
            MsgBox("也就是一般習慣稱的第" & sN + 1 & "個")
        Else
            MsgBox("未找到")
        End If
    End Sub
End Class

2008年12月26日 星期五

20106黎怡君 99-1

image

'1.將輸入之秒數轉換成「時:分:秒」。如輸入 10000,則輸出 02:46:40
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim t = 10000
        Dim sec = t Mod 60
        Dim minute = t \ 60 Mod 60
        Dim hour = t \ 3600
        MsgBox(hour & ":" & minute & ":" & sec)
    End Sub
End Class

20103莊筑鈞試貼

Hello

20101王芊頤試貼

HELLO

20107張純禎 99-1

image

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim t = 10000
        Dim sec = t Mod 60
        Dim minute = t \ 60 Mod 60
        Dim hour = t \ 3600
        MsgBox(hour & ":" & minute & ":" & sec)
    End Sub
End Class

20108陳一慈 99-1

image

'1.將輸入之秒數轉換成「時:分:秒」。如輸入 10000,則輸出 02:46:40。
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim t = 10000
        Dim sec = 10000 Mod 60
        Dim minute = t \ 60 Mod 60
        Dim hour = t \ 3600
        MsgBox(hour & ":" & minute & ":" & sec)
    End Sub
End Class

20109杜羚瑗

hello

20141王凱民

 

HOLLE

20102紀慈庭試貼

HELLO

20143葉俊佑

哈囉!

20122徐筱惠 99-1

image 

'1.將輸入之秒數轉換成「時:分:秒」。如輸入 10000,則輸出 02:46:40。
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim t = 10000
        Dim sec = t Mod 60
        Dim minute = t \ 60 Mod 60
        Dim hour = t \ 3600
        MsgBox(hour & ":" & minute & ":" & sec)
    End Sub
End Class

20112陳怡蒨

hello

20101王芊頤試貼

HELLO

麗山經典50題

http://203.64.52.1/~jennyher/research/problems50.txt

先從簡單的開始,慢慢就會進入狀況,有空就解個一二題,假以時日,您會寫出興趣來,也會很有成就感。

彰商程式設計隊網站

http://berlin.chsc.chc.edu.tw/VBMaster/main.htm

 

有很多精采的資源,一定要去逛逛

彰商程式設計隊的99題練習題

http://berlin.chsc.chc.edu.tw/VBMaster/upload/Question99.txt

觀摩一下其他學校的訓練情形吧!

2008年12月24日 星期三

氣泡排序 -- 含過程

image

Public Class Form1
    Dim i, j
    Dim str1 = ""
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '原資料
        Dim a() = {5, 4, 3, 2, 1}

        '排序前資料記錄
        str1 = "原資料" & vbNewLine
        str1 = str1 & a(0) & a(1) & a(2) & a(3) & a(4) & vbNewLine
        str1 = str1 & "-- 過程 -- " & vbNewLine

        '排序
        For j = 0 To 3
            For i = 0 To 3
                If a(i) > a(i + 1) Then
                    Dim t = a(i)
                    a(i) = a(i + 1)
                    a(i + 1) = t
                End If
            Next i
            '排序過程資料記錄
            str1 = str1 & a(0) & a(1) & a(2) & a(3) & a(4) & vbNewLine
        Next j

        '最後結果輸出
        MsgBox(str1)
    End Sub
End Class

VB learning啟用公告

201班同學
尚未取得可上傳資料邀請同學,請再次Mail您的 班級座號姓名至
vb945935@gmail.com

吳進北

Visual Basic自學輔導注意事項

網址:http://test.gotop.com.tw/

帳號:jackcyhs

虛擬教室7

教科書

教35 章節ch1-ch5 或 教34 前100題

測驗者姓名:班級座號姓名 例:料三甲50王小美

12/24 日測驗者以60分為及格分數

12/31日前自行上機補考者以70分為及格分數

排名排序Sample


Public Class Form1
Dim str1 = ""
Dim i, j
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'原始資料
Dim a() = {92, 83, 95, 71, 94}
Dim r(5)

'排序前資料輸出
For i = 0 To 4
str1 = str1 & a(i) & " "
Next
MsgBox(str1)

'排名排序
For j = 0 To 4
r(j) = 1
For i = 0 To 4
If a(j) < a(i) Then r(j) = r(j) + 1
Next
Next

'排序後資料輸出
str1 = ""
For i = 0 To 4
str1 = str1 & a(i) & " " & "名次:" & r(i) & vbNewLine
Next
MsgBox(str1)
End Sub
End Class

2008年12月23日 星期二

排名排序





Public Class Form1
Dim str1 = ""
Dim i, j
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'原始資料
Dim a() = {92, 83, 95, 71, 94}
Dim r(5)

'排序前資料輸出
For i = 0 To 4
str1 = str1 & a(i) & " "
Next
MsgBox(str1)

'排名排序
For j = 0 To 4
r(j) = 1
For i = 0 To 4
If a(j) < a(i) Then r(j) = r(j) + 1
Next
Next

'排序後資料輸出
str1 = ""
For i = 0 To 4
str1 = str1 & a(i) & " " & "名次:" & r(i) & vbNewLine
Next
MsgBox(str1)
End Sub
End Class

選擇排序














Public Class Form1
Dim str1 = ""
Dim i, j
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'原始資料
Dim a() = {2, 3, 5, 1, 4}

'排序前資料輸出
For i = 0 To 4
str1 = str1 & a(i) & " "
Next
MsgBox(str1)

'選擇排序 - 由小至大
For j = 0 To 3
For i = j + 1 To 4
If a(j) > a(i) Then
Dim t = a(j)
a(j) = a(i)
a(i) = t
End If
Next i
Next j

'排序後資料輸出
str1 = ""
For i = 0 To 4
str1 = str1 & a(i) & " "
Next
MsgBox(str1)
End Sub
End Class




氣泡排序


Public Class Form1
Dim i, j
Dim str1 = ""
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'原始資料
Dim a() = {3, 2, 5, 1, 4}

'排序前資料輸出
For i = 0 To 4
str1 = str1 & a(i) & " "
Next i
MsgBox(str1)

'排序
For j = 0 To 3
For i = 0 To 3
If a(i) > a(i + 1) Then
Dim t = a(i)
a(i) = a(i + 1)
a(i + 1) = t
End If
Next i
Next j

'排序後資料輸出
str1 = ""
For i = 0 To 4
str1 = str1 & a(i) & " "
Next i
MsgBox(str1)
End Sub
End Class

2008年12月19日 星期五

求第1大、第2大值 ... -- 氣泡排序基礎









'求第1大、第2大值 ... -- 氣泡排序基礎
Public Class Form1

Dim i, j

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim a() = {2, 5, 4, 1, 3}

For j = 1 To 4

For i = 0 To 3

If a(i) > a(i + 1) Then

Dim t = a(i)

a(i) = a(i + 1)

a(i + 1) = t

End If

Next

Next j

For i = 0 To 4

MsgBox(a(i))

Next i

End Sub

End Class