close
How many 0's? (2)上一篇不打算刪了,直接再貼一篇原本有兩個演算法,礙於VB6一些除法運算(整除與餘數)的溢位問題,必須要用到效率比較低的字串運算法其實可以自己寫一些大數的除法運算,但是為了程式的易讀性,先不這麼做,兩種程式碼我都會貼上來。先來個不重要的程式前半部:  1: Private Declare Function GetTickCount Lib "kernel32" () As Long 2:   3: Private Sub Command1_Click() 4: Me.AutoRedraw = True 5: Cls 6:   7: Print HMOs(10, 11) 8: Print HMOs(100, 200) 9: Print HMOs(0, 500) 10: Print HMOs("1234567890", "2345678901") 11: Print HMOs("0", "4294967295") 12: Print HMOs("-1", -1) 13: End Sub 14:   15: Private Sub Command2_Click() 16: Dim i As Double 17: Dim nowtick As Long 18: 19: Me.AutoRedraw = True 20: Me.Caption = "請稍等,跑個幾秒很正常" 21: Cls 22: DoEvents 23: 24: nowtick = GetTickCount 25: For i = 10 ^ 8 To 10 ^ 8 + 10 ^ 5 26: Call HMOs(0, i) 27: Next 28: nowtick = (GetTickCount - nowtick) 29: Print "範圍: m=0, n=(10^8) 到 (10^8)+(10^5), 迴圈總計10^5次" 30: Print "總花費時間: "; nowtick; "毫秒" 31: Print "平均每次花費時間"; nowtick / 10 ^ 5; "毫秒" 32: End Sub 33:   34: Private Function HMOs(ByVal min As Double, _ 35: ByVal max As Double) As Double 36: If (CDbl(max) < 0) Or _ 37: (CDbl(min) < 0) Or _ 38: (CDbl(max) < CDbl(min)) Then 39: HMOs = -1 40: Else 41: HMOs = HMOs_zero(max) - HMOs_zero(min - 1) 42: '傳回(0~max)的"0"數量 - (0~min-1)的"0"數量 43: End If 44: End Function.
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 bb111543 的頭像
    bb111543

    肉毒桿菌

    bb111543 發表在 痞客邦 留言(0) 人氣()