2012年9月3日 星期一

撲克牌的判斷

輸入5張牌
判斷是什麼牌型。

輸入:
黑桃A 黑桃2 黑桃3 黑桃4 黑桃5

輸出:
同花順

2 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Dim a(4, 13), b(4), b1(4)
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    For i = 1 To 4
    For j = 1 To 13
    a(i, j) = 0
    Next
    Next
    Do While Not EOF(1)
    List1.Clear
    Line Input #1, x
    c = Split(x, " ")
    b(1) = "A": b(2) = "J": b(3) = "Q": b(4) = "K"
    b1(1) = "1": b1(2) = "11": b1(3) = "12": b1(4) = "13"
    For i = 0 To UBound(c)
    For j = 1 To 4
    c(i) = Replace(c(i), b(j), b1(j))
    Next
    If Len(c(i)) = 3 Then
    If Mid(c(i), 1, 2) = "黑桃" Then a(1, Right(c(i), 1)) = Right(c(i), 1)
    If Mid(c(i), 1, 2) = "紅心" Then a(2, Right(c(i), 1)) = Right(c(i), 1)
    If Mid(c(i), 1, 2) = "方塊" Then a(3, Right(c(i), 1)) = Right(c(i), 1)
    If Mid(c(i), 1, 2) = "梅花" Then a(4, Right(c(i), 1)) = Right(c(i), 1)
    Else
    If Mid(c(i), 1, 2) = "黑桃" Then a(1, Right(c(i), 2)) = Right(c(i), 2)
    If Mid(c(i), 1, 2) = "紅心" Then a(2, Right(c(i), 2)) = Right(c(i), 2)
    If Mid(c(i), 1, 2) = "方塊" Then a(3, Right(c(i), 2)) = Right(c(i), 2)
    If Mid(c(i), 1, 2) = "梅花" Then a(4, Right(c(i), 2)) = Right(c(i), 2)
    End If
    Next
    For i = 1 To 4
    For j = 1 To 13
    If a(i, j) <> 0 Then List1.AddItem i & " " & (a(i, j) + 100)
    Next
    Next
    Loop
    s = 1
    s1 = 1
    s3 = 1
    For i = 1 To (List1.ListCount - 1)
    d = Split(List1.List(i), " ")
    e = Split(List1.List(i - 1), " ")
    If Val(e(1)) = Val(d(1) - 1) Then
    If e(0) = d(0) Then s1 = s1 + 1 Else s1 = 1
    s = s + 1
    Else
    s = 1
    End If
    If e(0) = d(0) Then s3 = s3 + 1
    Next
    If s = 5 And s1 = 5 Then
    Print #2, "同花順"
    ElseIf s = 5 Then Print #2, "順子"
    ElseIf s3 = 5 Then Print #2, "同花"
    End If
    s1 = 0
    s2 = 0
    For i = 0 To (List1.ListCount - 1)
    s = 0
    d = Split(List1.List(i), " ")
    For j = 0 To (List1.ListCount - 1)
    e = Split(List1.List(j), " ")
    If d(1) = e(1) Then s = s + 1
    Next
    If s = 2 Then s1 = s1 + 1
    If s = 3 Then s2 = s2 + 1
    Next
    If s = 4 Then
    Print #2, "鐵支"
    ElseIf s2 > 1 And s1 >= 1 Then Print #2, "葫蘆"
    ElseIf s2 > 1 And s1 < 1 Then Print #2, "三條"
    ElseIf s1 = 4 Then Print #2, "二對"
    ElseIf s1 = 2 Then Print #2, "一對"
    End If
    Close
    Close
    End
    End Sub

    回覆刪除
  2. Dim a(4) As String
    Dim b(4) 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
    Line Input #1, n
    aa = Split(n, " ")
    For i = 0 To UBound(aa)
    'b(i) = aa(i)
    a(i) = aa(i)
    Next i
    c = Array("A", "J", "Q", "K")
    bb = Array("1", "11", "12", "13")
    For i0 = 0 To UBound(a) 'AJQK換
    For j0 = 0 To UBound(bb)
    a(i0) = Replace(a(i0), c(j0), bb(j0))
    Next j0
    Next i0
    For i = 0 To UBound(a)
    If Len(a(i)) = 4 Then b(i) = Val(Right(a(i), 2)) Else b(i) = Val(Right(a(i), 1))
    Next i
    For k = 0 To UBound(b) - 1
    For u = 0 To UBound(b) - 1
    If b(u) > b(u + 1) Then
    t = b(u + 1)
    b(u + 1) = b(u)
    b(u) = t
    End If
    Next u
    Next k
    Call check
    Close #2
    Close #1
    End
    End Sub
    Sub check()
    Dim t As Boolean
    Dim f As Boolean
    Dim c As Boolean
    s = 1: s1 = 1
    For j = 0 To UBound(a) - 1
    If b(j) = b(j + 1) - 1 Then s1 = s1 + 1 Else s1 = 1 '相差為1 = 順
    If Left(a(j), 2) = Left(a(j + 1), 2) Then s = s + 1 Else s = 1 '花色
    Next j
    If s = 5 Then
    If s1 = 5 Then
    Print #2, "同花順"
    Else
    Print #2, "同花"
    End If

    Else
    If s1 = 5 Then Print #2, "順子"

    s = 1: s1 = 1: t = False: f = False: c = False
    For k = 0 To UBound(a) - 1
    If s = 4 Then t = True
    If s = 3 Then f = True
    If s = 2 Then c = True
    If b(k) = b(k + 1) Then
    s = s + 1
    s1 = s1 + 1
    Else
    s = 1
    End If
    Next k
    If t = True Then Print #2, "鐵支"
    If f = True And s = 2 Then Print #2, "葫蘆"
    If f = True And s = 1 Then Print #2, "三條"
    If t = False And s1 = 3 Then Print #2, "兩對"
    If c = True And s1 < 3 Then Print #2, "一對"
    End If
    End Sub

    回覆刪除