2012年11月5日 星期一

音源線

這是一種"1公2母"的音源線,就是有一個輸入端兩個輸出端的線。
如今,有人想要在畢旅同時使多台音響播放,請問他需要幾條音源線才夠 ?


輸入說明:
只有一行,代表有n台音響 , 0<n<32768


輸入範例:
1024
輸出範例:
1023

8 則留言:

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

    x = 0
    If n < 2 Or n = 2 Then x = 1
    If n > 2 Then x = n - 1

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

    回覆刪除
  2. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, x
    If x <= 2 Then ans = 1
    If x > 2 Then ans = x - 1
    Print #2, ans
    Close
    Close
    End
    End Sub

    回覆刪除
  3. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, n
    If n > 1 Then a = n - 1
    If n = 1 Then a = 1
    Print #2, a
    Close
    Close
    End
    End Sub

    回覆刪除
  4. 作者已經移除這則留言。

    回覆刪除
  5. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, n
    If n = 1 Then
    t = 1
    Else
    t = n - 1
    End If
    Print #2, t
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  6. 以上程式正確:)

    另外如果輸入n範圍是0<=n<32768的話要檢查0喔(邊界值)

    回覆刪除
  7. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, x
    If (x <= 2) And (x = 0) Then ans = 1
    If x > 2 Then ans = x - 1
    Print #2, ans
    Close
    Close
    End
    End Sub

    回覆刪除
  8. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, a
    If a = 0 Then
    Print #2, 0
    ElseIf a < 2 Then
    Print #2, 1
    Else
    Print #2, a - 1
    End If
    Close
    End
    End Sub

    回覆刪除