2012年11月20日 星期二

5/21程式小考_2nd



讀入兩數,並將兩數字間所有的數字各自拆開,並輸出最多者與其各數。
    (若個數相等,則輸出數字最大者)
輸入範例:10 12
輸出範例:1 4

1 則留言:

  1. Dim former, latter, max As Integer
    Dim strr, maxstr As String
    Private Sub Form_Load()
    max = 0
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, former, latter
    For i = former To latter
    strr = strr & Str(i)
    Next
    For i = 0 To 9
    ori = Len(strr)
    strr = Replace(strr, i, "")
    If ori - Len(strr) > max Then max = ori - Len(strr): maxstr = i
    If Len(strr) = 0 Then Exit For
    Next
    Print #2, maxstr & " " & max
    Close #2
    Close #1
    End
    End Sub

    回覆刪除