2012年11月20日 星期二

5/21程式小考_5th


三顆公正的骰子,請輸出總和為n的所有組合。
輸入範例: 3
輸出範例: 1 1 1

3 則留言:

  1. Dim num As Integer
    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, num
    For i = 1 To 6
    For ii = 1 To 6
    For iii = 1 To 6
    If i + ii + iii = num Then Print #2, i & " " & ii & " " & iii
    Next
    Next
    Next
    Close #2
    Close #1
    End
    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, n
    For i = 1 To 6
    For j = 1 To 6
    For k = 1 To 6
    If i + j + k = n Then Print #2, i & " " & j & " " & k
    Next
    Next
    Next
    Close #2
    Close #1
    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, x
    For a = 1 To 6
    For b = 1 To 6
    For C = 1 To 6
    If a + b + C = x Then Print #2, a & " " & b & " " & C
    Next
    Next
    Next
    Close
    Close
    End
    End Sub

    回覆刪除