2011年1月10日 星期一

2010第一次儲備選手選拔試卷第一題

找出最小數字:從指定目錄中的"in.txt",讀入一數字字串,以逗號分隔,找出字串中最小字數。
輸出到指定目錄的"out.txt"。
(讀取指定目錄的in.txt, 請用 open app.path & "\in.txt" for input as #1 )
※今後皆以指定目錄形式完成VB

輸入範例:
26,56,78,99,15,13

輸出範例:
13

6 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\out.txt" For Output As #2
    Open App.Path & "\in.txt" For Input As #1
    Input #1, x

    Do While Not EOF(1)

    Input #1, y
    If x > y Then x = y

    Loop
    Print #2, x

    Close #1
    Close #2

    End
    End Sub

    回覆刪除
  2. 緣尉好,
    這題OK。(雖然似乎和12月開始的arro有重複,沒關係啦,這兒空間不是問題。)
    熊掌

    回覆刪除
  3. Private Sub Form_Load()
    Me.Hide
    Dim a, b
    Open App.Path & "\in.txt" For Input As #1


    Input #1, b
    Do While Not EOF(1)
    Input #1, a
    If a < b Then b = a
    Loop

    Close #1


    Open App.Path & "\out.txt" For Output As #2

    Print #2, b

    Close #2
    End
    End Sub

    回覆刪除
  4. Dim n As Integer
    Dim A As Integer

    Private Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Input #1, n

    Do While Not EOF(1)
    Input #1, A
    If n > A Then n = A
    Loop

    Close #1

    Open App.Path & "\out.txt" For Output As #2
    Print #2, n
    Close #2
    End
    End Sub

    回覆刪除
  5. Arro,佑好,
    程式正確。
    熊掌

    回覆刪除
  6. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Line Input #1, n
    Call A1(n)
    Close
    Close
    End
    End Sub

    Sub A1(a)
    Dim s, m
    m = 99999
    s = Split(a, ",")
    For i = 0 To UBound(s)
    If Val(s(i)) < m Then m = s(i)
    Next
    Print #2, m
    End Sub


    1:45

    回覆刪除