2012年11月5日 星期一

1000 到 9999 不重複的數

從 1000 到 9999 中找出數字不能重複的數,並將符合條件者全部印出。


例如: 1234

4 則留言:

  1. Dim ok(9999) As Boolean
    Private Sub Form_Load()

    Open App.Path & "\out.txt" For Output As #2
    For ai = 1000 To 9999
    For i = 1 To 3
    For ii = i + 1 To 4
    If Mid(ai, i, 1) = Mid(ai, ii, 1) Then ok(ai) = True
    Next
    Next
    Next

    For iii = 1000 To 9999
    If ok(iii) = False Then Print #2, iii
    Next
    Close #2

    End Sub

    回覆刪除
  2. Private Sub Form_Load()
    Me.Hide
    Dim s As Boolean
    Open App.Path & "\out.txt" For Output As #2
    For i = 1000 To 9999
    s = False
    For j = 1 To 3
    For k = j + 1 To 4
    If Mid(i, j, 1) = Mid(i, k, 1) Then s = True: Exit For

    Next
    If s = True Then Exit For
    Next

    If s = False Then Print #2, i
    Next
    Close
    End
    End Sub

    回覆刪除
  3. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\out.txt" For Output As #1
    For i = 1000 To 9999
    a = Right(i, 1)
    b = Mid(i, 3, 1)
    c = Mid(i, 2, 1)
    d = Left(i, 1)
    If a <> b And a <> c And a <> d And b <> c And b <> d And c <> d Then
    Print #1, d & c & b & a
    End If
    Next
    Close #1
    End
    End Sub

    回覆刪除
  4. 三位程式正確
    復陞可以試試用迴圈的方式思維

    回覆刪除